Next Page > Hide TOC

Legacy Documentclose button

Important: The information in this document is obsolete and should not be used for new development.

NSAutoreleasePool

Inherits from
Object
Package
com.apple.cocoa.foundation
Companion guide

Overview

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);

Tasks

Creating a Pool

Freeing a Pool

Static Methods

pop

Indicates that you are finished using the NSAutoreleasePool identified by pool.

public static void pop(int pool)

See Also

push

Creates an NSAutoreleasePool and returns an identifier to it.

public static int push()

See Also


Next Page > Hide TOC


© 1997, 2006 Apple Computer, Inc. All Rights Reserved. (Last updated: 2006-07-24)


Did this document help you?
Yes: Tell us what works for you.
It’s good, but: Report typos, inaccuracies, and so forth.
It wasn’t helpful: Tell us what would have helped.