FROM : j o a r
DATE : Tue Feb 12 23:20:46 2008
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
DATE : Tue Feb 12 23:20:46 2008
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 mail archive

