Re: In-loop releasing of objects does not free memory?
Re: In-loop releasing of objects does not free memory?
- Subject: Re: In-loop releasing of objects does not free memory?
- From: j o a r <email@hidden>
- Date: Tue, 12 Feb 2008 14:20:46 -0800
On Feb 12, 2008, at 2:10 PM, Arthur C. wrote:
I am writing a Cocoa-program to reduce a large amount of measurement
data.
This involves reading in large files, like 6 MB each, in a loop over
about 60 of them.
I try to release as many temporary objects as possible whenever I'm
finished with them. However, the memory is not freed, as can be seen
using Activity monitor, and by a dramatic slowdown due to memory
overflow.
So the question is, how can I get the memory back? I need it for the
next file(s)...
Code looks like this:
NSArray * files; // contains a list of filenames
for(i=0;i<[files count]; i++)
{
NSString * dataFromFile = [[NSString alloc] initWithContentsOfFile:
[files objectAtIndex: i]];
< some processing >
[dataFromFile release];
}
Autoreleased instances behave the same, i.e. no memory gets really
freed.
Two suggestions:
* Use Instruments to figure out exactly what type of objects that
you're "leaking" in your loop
* Try inserting a local autorelease pool in the loop. You might be
using some API that creates autoreleased objects.
j o a r
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden