Skip to content

Instantly share code, notes, and snippets.

@lukhnos
Last active September 4, 2015 15:34
Show Gist options
  • Save lukhnos/65840aa045d79c98bf1f to your computer and use it in GitHub Desktop.
Save lukhnos/65840aa045d79c98bf1f to your computer and use it in GitHub Desktop.
Demonstrates that Throwable leaks memory in j2objc, see https://github.com/google/j2objc/issues/601
import com.google.j2objc.annotations.AutoreleasePool;
public class ThrowableLeaks {
public static void main(String args[]) {
for (int i = 0; ; i++) {
foo(i);
bar(i);
try {
Thread.sleep(1000);
} catch (Exception e) {
}
}
}
@AutoreleasePool
public static void foo(int i) {
System.out.println(i);
try {
if ((i % 20) == 0) {
throw new AssertionError("lost");
}
} catch (Throwable e) {
}
}
@AutoreleasePool
public static void bar(int i) {
if ((i % 30) == 0) {
new Throwable("something");
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment