sclass guessDeepObjectSize_recursive_Data { long size; Set stack = identityHashSet(); Set seen = identityHashSet(); } static long guessDeepObjectSize_recursive(O o) { if (o == null) ret 0; new guessDeepObjectSize_recursive_Data data; data.stack.add(o); while ping (nempty(data.stack)) { ifdef guessDeepObjectSize_recursive_debug print("gos stack size: " + l(data.stack)); endifdef guessDeepObjectSize_recursive_step(data, popFirst(data.stack)); } ret data.size; } svoid guessDeepObjectSize_recursive_step(guessDeepObjectSize_recursive_Data data, O o) { if (!data.seen.add(o)) ret; ifdef guessDeepObjectSize_recursive_debug print("gos: " + getClassName(o)); endifdef if (o instanceof Class) ret; /*if (o cast S) ret with data.size += guessStringSize(o); if (o cast ArrayList) { data.stack.addAll(o); }*/ if (isArray(o)) { ret; // TODO } data.size += unsafe_sizeOf(o); for (Field f : allFieldObjects(o)) pcall-short { O x = f.get(o); if (x != null && !data.seen.contains(x)) { data.stack.add(x); ifdef guessDeepObjectSize_recursive_debug print("gos found: " + getClassName(o) + " " + identityHashCode(o) + " " + o); endifdef } } //fail("can't handle object type: " + className(o)); }