Skip to content

Instantly share code, notes, and snippets.

@lukhnos
Last active September 4, 2015 15:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • 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