Re: Losing my memory - a caching problem?
Re: Losing my memory - a caching problem?
- Subject: Re: Losing my memory - a caching problem?
- From: Stuart Rogers <email@hidden>
- Date: Wed, 18 Aug 2010 12:50:16 +0100
On 18 Aug 2010, at 01:26, Shawn Erickson wrote:
>
> So in general you shouldn't worry about free RAM shrinking to a sliver
> of total system RAM over time... however if your application loads
> file data (aka image data in your case) only once or it is unlikely
> your application will load the same file data again in the reasonable
> near future then you should look at disabling file caching of the file
> data you load.
I think we have a winner! I've just implemented Shawn's suggestion
and it seems to solve my problem. I've just passed 9,695 image files
through my code's test phase (at 1.2MB apiece, that's over 11GB of
data) and I still have over 6.4GB marked as free. I am a very happy
bunny!
(That's not to invalidate Ken's suggestion that CoreImage is caching
stuff - each time I run my test I'm losing a little more memory, but it's
on the level of noise compared to turning off file caching.)
Thanks very much to everyone who contributed to this!
For the record, my non-caching code looks like this (error handling snipped):
- (ImageSignature *)signatureForPath:(NSString *)path
{
ImageSignature *sig = nil;
NSData *data = [NSData dataWithContentsOfFile:path options:NSUncachedRead error:nil];
NSDictionary *opts = [NSDictionary dictionaryWithObject:(id)kCFBooleanFalse
forKey:(NSString*)kCGImageSourceShouldCache];
CGImageSourceRef src = CGImageSourceCreateWithData((CFDataRef)data,(CFDictionaryRef)opts);
if (src)
{
CGImageRef img = CGImageSourceCreateImageAtIndex(src,0,(CFDictionaryRef)opts);
CFRelease(src);
if (img)
{
sig = [self signatureForImage:img];
CGImageRelease(img);
}
}
return sig;
}
Stuart
_______________________________________________
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