This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import com.google.j2objc.annotations.AutoreleasePool; | |
| import java.io.File; | |
| import java.io.FileOutputStream; | |
| import java.io.IOException; | |
| import java.nio.channels.FileChannel; | |
| import java.nio.channels.FileLock; | |
| public class NIOLeaks { | |
| public static void main(String args[]) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // This works perfectly as a Java program, but produces wrong output when | |
| // translated into Objective-C. Can you spot why? | |
| import java.util.Arrays; | |
| import java.util.Iterator; | |
| import java.util.List; | |
| public class FastEnumGotcha { | |
| static class Wrapper<T> { | |
| T value; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // Solution 1: Use annotation. | |
| import com.google.j2objc.annotations.LoopTranslation; | |
| import java.util.Arrays; | |
| import java.util.Iterator; | |
| import java.util.List; | |
| public class FastEnumGotcha { | |
| static class Wrapper<T> { | |
| T value; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // Solution 2: Use OCNI. | |
| import java.util.Arrays; | |
| import java.util.Iterator; | |
| import java.util.List; | |
| public class FastEnumGotcha { | |
| static class Wrapper<T> { | |
| T value; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /** | |
| * This demonstrates the leaks in ReferenceQueue. | |
| * | |
| * To run the demo, compile the source with: | |
| * | |
| * j2objc ReferenceQueueLeaks.java | |
| * j2objcc ReferenceQueueLeaks.m | |
| * | |
| * Then use the Leaks tool in Instruments and have it run "a.out ReferenceQueueLeaks". | |
| */ |
OlderNewer