• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: NSImage leaks on every draw?! Help!
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: NSImage leaks on every draw?! Help!


  • Subject: Re: NSImage leaks on every draw?! Help!
  • From: "Ben Kennedy" <email@hidden>
  • Date: Thu, 24 Oct 2002 23:12:53 -0400
  • Organization: Zygoat Creative Technical Services

On 24,10,02 at 5:13 pm -0400, Lance Bland wrote:

>just for kicks can you put a [img recache] in there and try it.

Where abouts specifically?

Here's a concrete example of where things don't make sense to me. My
resetCursorRects method:

- (void) resetCursorRects
{
// determine cursor rect for visible active area of all patterns
NSRect r = [self visibleRect];
r.origin.y = DIV_RECT_SIZE;
r.size.height = DIV_RECT_SIZE * kNumGridPos;

// create a shrunken version of current drum icon for the menuitem
NSImage *image = [[currDrum sourceImage] copy];
NSCursor *newCurs;
[image setDataRetained:NO]; // please just keep the small bitmap
[image setCacheMode:NSImageCacheAlways]; // like i said
[image setScalesWhenResized:YES]; // yep, shrink it
[image setSize:NSMakeSize(16,16)]; // ...to this size please
[image recache]; // ?!
NSLog(@"image reps: %@",[image representations]);
newCurs = [[NSCursor alloc] initWithImage:image hotSpot:NSMakePoint(7,7)];
[image release];

// swap in the new cursor
[mouseCursor release];
mouseCursor = newCurs;
[self addCursorRect:r cursor:mouseCursor];
[mouseCursor setOnMouseEntered:YES];

return;
}

Every time resetCursorRects runs, memory is leaked courtesy of NSImage.
Something that puzzles me is the output of the above NSLog call, which
always looks like this:

2002-10-24 23:06:09.139 Doggiebox[16449] image reps: <CFArray 0x12e8230
[0xa01303fc]>{type = mutable-small, count = 1, values = (
0 : NSPDFImageRep 0x278a50 Size={80, 80}
ColorSpace=NSCalibratedRGBColorSpace BPS=0 Pixels=0x0 Alpha=NO
)}

Note how there is STILL an NSPDFImageRep, whose size is 80x80. Didn't I
just tell the damn image to not only dispose of its original data, but
also to resize itself to 16x16? What's going on here?

Furthermore, I don't understand [NSImage recache]. The documentation says:

>Invalidates the off-screen caches of all representations and frees them.
>The next time any representation is composited, it will first be asked to
>redraw itself in the cache. NSCachedImageReps aren't destroyed by this
method.

What is the meaning of "the cache" vs. "NSCachedImageReps" in this
discussion? From reading the developer docs on Drawing & Imaging
(NSImage and its associated classes), my understanding is that NSImage
caches its off-screen representations in NSCachedImageReps. Am I
confusing two separate types of caching here?

-ben


--
Ben Kennedy, chief magician
zygoat creative technical services
613-228-3392 | 1-866-466-4628
http://www.zygoat.ca
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.

  • Follow-Ups:
    • Re: NSImage leaks on every draw?! Help!
      • From: "Ben Kennedy" <email@hidden>
  • Prev by Date: New document does NOT open at program start!
  • Next by Date: Re: NSDivideRect and NSInsertRect functions
  • Previous by thread: Re: NSImage leaks on every draw?! Help!
  • Next by thread: Re: NSImage leaks on every draw?! Help!
  • Index(es):
    • Date
    • Thread