Important: The information in this document is obsolete and should not be used for new development.
Inherits from | Object |
Package | com.apple.cocoa.foundation |
Companion guide |
An autorelease pool is used to manage Foundation’s autorelease mechanism for Objective-C objects. NSAutoreleasePool provides Java applications access to autorelease pools. Typically it is not necessary for Java applications to use NSAutoreleasePools since Java manages garbage collection. However, some situations require an autorelease pool; for instance, if you start off a thread that calls Cocoa, there won’t be a top-level pool.
You know you need an autorelease pool when you see “no pool in place - just leaking” warnings coming from your Cocoa Java application. Just wrap pools around the places where you have top-level Java threads calling into Cocoa. Use code like the following to accomplish this task:
int myPool = NSAutoreleasePool.push(); |
// Your code here |
NSAutoreleasePool.pop(myPool); |
Indicates that you are finished using the NSAutoreleasePool identified by pool.
public static void pop
(int pool)
Creates an NSAutoreleasePool and returns an identifier to it.
public static int push
()
© 1997, 2006 Apple Computer, Inc. All Rights Reserved. (Last updated: 2006-07-24)