FROM : Murat Konar
DATE : Fri Nov 30 22:07:33 2007
On Nov 30, 2007, at 12:19 PM, Alexander Cohen wrote:
> What im doing is pretty simple. I have a loop that for each
> iteration, opens an image, gets some info, then closes it down
> ( using CG of course ). Everything is released correctly and there
> are no leaks. BUt after a while, the system gets unresponsive.
But *when* are things being released?
A common problem when running in a loop is that objects that are
autoreleased (so-called temporary objects) aren't actually
deallocated until the end of the current run-loop. Often, these
temporary objects aren't ones you've created; they're created as a
side effect of code that you're calling.
You can avoid the build-up of temporary objects by using your own
auto-release pool thusly (typed in Mail, this is just pseudo code to
illustrate the concept):
NSAutoreleasePool * autoreleasePool = [[NSAutoreleasePool alloc]init];
while (keepLooping)
{
do stuff...
if (number of loops since the last time we released the
autoreleasePool is above some threshold)
{
[autoreleasePool release];
autoreleasePool = [[NSAutoreleasePool alloc]init];
}
}
[autoreleasePool release];
How often you release the autorelease pool depends on how memory
heavy your operations are.
_murat
DATE : Fri Nov 30 22:07:33 2007
On Nov 30, 2007, at 12:19 PM, Alexander Cohen wrote:
> What im doing is pretty simple. I have a loop that for each
> iteration, opens an image, gets some info, then closes it down
> ( using CG of course ). Everything is released correctly and there
> are no leaks. BUt after a while, the system gets unresponsive.
But *when* are things being released?
A common problem when running in a loop is that objects that are
autoreleased (so-called temporary objects) aren't actually
deallocated until the end of the current run-loop. Often, these
temporary objects aren't ones you've created; they're created as a
side effect of code that you're calling.
You can avoid the build-up of temporary objects by using your own
auto-release pool thusly (typed in Mail, this is just pseudo code to
illustrate the concept):
NSAutoreleasePool * autoreleasePool = [[NSAutoreleasePool alloc]init];
while (keepLooping)
{
do stuff...
if (number of loops since the last time we released the
autoreleasePool is above some threshold)
{
[autoreleasePool release];
autoreleasePool = [[NSAutoreleasePool alloc]init];
}
}
[autoreleasePool release];
How often you release the autorelease pool depends on how memory
heavy your operations are.
_murat
| Related mails | Author | Date |
|---|---|---|
| Alexander Cohen | Nov 30, 14:53 | |
| Thomas Davie | Nov 30, 15:41 | |
| Alexander Cohen | Nov 30, 17:36 | |
| Gammah Radiation | Nov 30, 18:00 | |
| Alastair Houghton | Nov 30, 19:01 | |
| Murat Konar | Nov 30, 21:05 | |
| Alexander Cohen | Nov 30, 21:19 | |
| Shawn Erickson | Nov 30, 21:30 | |
| Murat Konar | Nov 30, 22:07 |






Cocoa mail archive

