NSInvalidArgumentException: *** -[NSAutoreleasePool retain]: Cannot retain an autorelease pool

171 views
Skip to first unread message

Laurent

unread,
Feb 9, 2010, 8:36:18 PM2/9/10
to F-Script
Hello,

I'm playing with injection of F-Script inside an application.

I was able to automate my process (a long loop that open a new file
each time) with a small F-script code, like this :

1 to:100000 do:[
launchMethodOfTheApplicationThatINeed. (take some important memory at
each call)
]

But, as the memory isn't freeing, my memory swap very quickly. So I
tried to add :

localPool := NSAutoreleasePool new.
launchMethodOfTheApplicationThatINeed. (take some important memory at
each call)
localPool drain.

but the alloc of NSAutoreleasePool give me the error :
NSInvalidArgumentException: *** -[NSAutoreleasePool retain]: Cannot
retain an autorelease pool

Any ideas on how to solve this Issue?

Thanks.

-- Laurent

ps: Apologize for my English :-(

Philippe Mougin

unread,
Feb 9, 2010, 9:12:54 PM2/9/10
to F-Script
In Cocoa, autorelease pools cannot be retained. When you assign your
newly created autorelease pool to the localPool variable, F-Script
tries to retain it, which leads to the error you get. One solution is
to manage your pool through an NSValue configured to not retain its
value. This gives:

poolHolder := NSValue valueWithNonretainedObject:NSAutoreleasePool


new.
launchMethodOfTheApplicationThatINeed. (take some important memory at
each call)

poolHolder nonretainedObjectValue drain.

Laurent

unread,
Feb 9, 2010, 9:28:25 PM2/9/10
to F-Script

On Feb 10, 3:12 am, Philippe Mougin <pmou...@acm.org> wrote:
> One solution is
> to manage your pool through an NSValue configured to not retain its
> value. This gives:

Perfect , "valueWithNonretainedObject" was exactly what I was looking
for.

Thanks a lot Philippe.

Reply all
Reply to author
Forward
0 new messages