Re: Core Image increases memory use a lot

2011-01-16 Thread Jeff Johnson
Hi Seth.

You might want to try putting an autorelease pool around your method. See the 
Tip in this document:

https://developer.apple.com/library/mac/#documentation/GraphicsImaging/Conceptual/CoreImaging/ci_tasks/ci_tasks.html%23//apple_ref/doc/uid/TP30001185-CH203-TPXREF101

I've used this tip before to fix what appeared to be a memory leak in my app.

-Jeff


On Jan 16, 2011, at 3:03 AM, Seth Willits wrote:

 I have a CALayer subclass and I'm drawing into it using Core Image. I'm 
 taking a CGImage, blurring, and adding a darkened radial gradient on top of 
 it. Pretty simple. Now the weird thing is, using Core Image for drawing this 
 image (instead of just drawing with no effects using CGContextDrawImage) 
 increases my app's memory usage by 30 MB. That almost doubles the entire 
 usage of my app. 
 
 It's not like I'm leaking any memory here, so why the large permanent 
 increase? I'd like to avoid it if I can because I'm getting criticized for 
 using too much memory despite it not being my fault. :-p
 
 
 
   - (void)drawInContext:(CGContextRef)theContext
   {
   CIImage * image = [CIImage 
 imageWithCGImage:(CGImageRef)self.backgroundImage];
   CGRect imageRect = [image extent];
   
   CIFilter * blur = [CIFilter filterWithName:@CIGaussianBlur];
   [blur setValue:image forKey:@inputImage];
   [blur setValue:[NSNumber numberWithInt:2] 
 forKey:@inputRadius];
   
   CIFilter * gradient = [CIFilter 
 filterWithName:@CIRadialGradient];
   CGPoint center = CGPointMake(CGRectGetMidX(imageRect), 
 CGRectGetMidY(imageRect));
   [gradient setValue:[CIVector vectorWithX:center.x Y:center.y]   
 forKey:@inputCenter];
   [gradient setValue:[NSNumber numberWithInt:0.0] 
 forKey:@inputRadius0];
   [gradient setValue:[NSNumber numberWithInt:600.0]   
 forKey:@inputRadius1];
   [gradient setValue:[CIColor colorWithRed:0.0 green:0.0 blue:0.0 
 alpha:0.3]  forKey:@inputColor0];
   [gradient setValue:[CIColor colorWithRed:0.0 green:0.0 blue:0.0 
 alpha:0.6]  forKey:@inputColor1];
   
   CIContext * context = [CIContext 
 contextWithCGContext:theContext options:NULL];
   CGRect extent = [image extent];
   [context drawImage:[blur valueForKey:@outputImage] 
 inRect:self.bounds fromRect:extent];
   [context drawImage:[gradient valueForKey:@outputImage] 
 inRect:self.bounds fromRect:extent];
   }
 
 
 
 --
 Seth Willits

___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: Core Image increases memory use a lot

2011-01-16 Thread Seth Willits



That's not applicable here. I'm not drawing many many things before returning 
to run loop so my memory usage isn't increasing due to repeated calls. It's 
just this single image. Just for giggles I tried it anyway, and as expected 
there's no difference at all.


--
Seth Willits






On Jan 16, 2011, at 5:32 AM, Jeff Johnson wrote:

 Hi Seth.
 
 You might want to try putting an autorelease pool around your method. See the 
 Tip in this document:
 
 https://developer.apple.com/library/mac/#documentation/GraphicsImaging/Conceptual/CoreImaging/ci_tasks/ci_tasks.html%23//apple_ref/doc/uid/TP30001185-CH203-TPXREF101
 
 I've used this tip before to fix what appeared to be a memory leak in my app.
 
 -Jeff
 
 
 On Jan 16, 2011, at 3:03 AM, Seth Willits wrote:
 
 I have a CALayer subclass and I'm drawing into it using Core Image. I'm 
 taking a CGImage, blurring, and adding a darkened radial gradient on top of 
 it. Pretty simple. Now the weird thing is, using Core Image for drawing this 
 image (instead of just drawing with no effects using CGContextDrawImage) 
 increases my app's memory usage by 30 MB. That almost doubles the entire 
 usage of my app. 
 
 It's not like I'm leaking any memory here, so why the large permanent 
 increase? I'd like to avoid it if I can because I'm getting criticized for 
 using too much memory despite it not being my fault. :-p
 
 
 
  - (void)drawInContext:(CGContextRef)theContext
  {
  CIImage * image = [CIImage 
 imageWithCGImage:(CGImageRef)self.backgroundImage];
  CGRect imageRect = [image extent];
  
  CIFilter * blur = [CIFilter filterWithName:@CIGaussianBlur];
  [blur setValue:image forKey:@inputImage];
  [blur setValue:[NSNumber numberWithInt:2] 
 forKey:@inputRadius];
  
  CIFilter * gradient = [CIFilter 
 filterWithName:@CIRadialGradient];
  CGPoint center = CGPointMake(CGRectGetMidX(imageRect), 
 CGRectGetMidY(imageRect));
  [gradient setValue:[CIVector vectorWithX:center.x Y:center.y]   
 forKey:@inputCenter];
  [gradient setValue:[NSNumber numberWithInt:0.0] 
 forKey:@inputRadius0];
  [gradient setValue:[NSNumber numberWithInt:600.0]   
 forKey:@inputRadius1];
  [gradient setValue:[CIColor colorWithRed:0.0 green:0.0 blue:0.0 
 alpha:0.3]  forKey:@inputColor0];
  [gradient setValue:[CIColor colorWithRed:0.0 green:0.0 blue:0.0 
 alpha:0.6]  forKey:@inputColor1];
  
  CIContext * context = [CIContext 
 contextWithCGContext:theContext options:NULL];
  CGRect extent = [image extent];
  [context drawImage:[blur valueForKey:@outputImage] 
 inRect:self.bounds fromRect:extent];
  [context drawImage:[gradient valueForKey:@outputImage] 
 inRect:self.bounds fromRect:extent];
  }
 
 
 
 --
 Seth Willits
 
 


___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: Core Image increases memory use a lot

2011-01-16 Thread Graham Cox

On 16/01/2011, at 8:03 PM, Seth Willits wrote:

 It's not like I'm leaking any memory here, so why the large permanent 
 increase? I'd like to avoid it if I can because I'm getting criticized for 
 using too much memory despite it not being my fault. :-p
 


Who complains about a 30MB memory usage increase these days? Who even notices? 
This is not Mac OS 9, it doesn't matter what your app's memory footprint is 
(within reason).

I expect Core Image is caching stuff for future use - blurs for example are 
expensive to set up. Might be worth comparing the time taken to execute the 
first time this is called with subsequent times - if there's a worthwhile speed 
up you can claim it as a feature - classic speed vs. memory tradeoff.

--Graham___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: Core Image increases memory use a lot

2011-01-16 Thread Seth Willits
On Jan 16, 2011, at 1:43 PM, Graham Cox wrote:

 It's not like I'm leaking any memory here, so why the large permanent 
 increase? I'd like to avoid it if I can because I'm getting criticized for 
 using too much memory despite it not being my fault. :-p
 
 
 Who complains about a 30MB memory usage increase these days? Who even 
 notices? This is not Mac OS 9, it doesn't matter what your app's memory 
 footprint is (within reason).

That's 30 MB for *a single image*. It happens multiple times and adds up. Who 
notices? Me, but also my customers (really). The recently released rewrite of 
my app QuickPick uses Core Animation and Core Image. It's a document and 
application launcher. Should it be using 150 MB? No. That's clearly excessive. 
Why is it using 150 MB? A little bit is my slight misuse of CA thinking it's 
smarter than it is, but almost 100 MB is just from using Core Image instead of 
Core Graphics.

If I remove just the blur filter, the memory usage isn't any lower. I can 
achieve the same effect (without the blur) using CG/NS and memory usage doesn't 
increase at all, as I would expect. 


 I expect Core Image is caching stuff for future use...

I have the same thought, but if I kill off the filter and every other 
CI-related object, I'd expect that to go away. Creating new filters and 
executing it again isn't significantly faster. 



--
Seth Willits



___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: Core Image increases memory use a lot

2011-01-16 Thread Nick Zitzmann

On Jan 16, 2011, at 2:43 PM, Graham Cox wrote:

 Who complains about a 30MB memory usage increase these days? Who even 
 notices? This is not Mac OS 9, it doesn't matter what your app's memory 
 footprint is (within reason).

Two kinds of people:

1. Experienced users that watch Activity Monitor like a hawk.

2. Unexperienced users that blame your program for slowing down their computer 
once its memory usage spikes and forces the OS to start swapping. Not everyone 
is literate enough to understand swapping, and since the OS outside of Activity 
Monitor gives the user no indication that this is going on (unless the disk is 
nearly full), then they need a scapegoat.

Using available memory is normally a good thing, since loading things from disk 
takes longer than accessing them from memory. But it is a balancing game, 
because using too much memory has negative side effects. So yes, it does 
matter, especially in 64-bit applications, since at least 32-bit apps will 
crash if they go overboard.

Nick Zitzmann
http://www.chronosnet.com/



___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com