WebObjects 4.x: "_NSAutoreleaseNoPool ... just leaking" Messages

This article discusses an issue with multithreaded Java apps and NSAutoreleasePools.

Symptom

When you spawn new Java worker threads in your WebObjects application, your console starts listing hundreds or thousands of messages like the following:


Solution

These messages are innocuous and should not affect your application, but they can be annoying because they can clutter a log file.

These messages appear because your Java code, in combination with the Java Bridge, is creating Objective-C objects. Objective-C uses "autorelease pools" for memory management. An autorelease pool gets created at the beginning of a request-response cycle for the main thread of a WebObjects application. If you spawn an additional thread in Java, you need to create an autorelease pool to manage the memory for the Objective-C objects that get created.

Insert the NSAutoreleasePool at the beginning of your Java thread's run() method:


- and release it at the end of the thread -

You'll need to do this for each thread you spawn because threads cannot share an NSAutoreleasePool.

Objective-C syntax

Note: This is the Objective-C equivalent of the Java push() and pop() methods above


Published Date: Feb 18, 2012