• 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: Leaking images
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Leaking images


  • Subject: Re: Leaking images
  • From: "John C. Randolph" <email@hidden>
  • Date: Fri, 21 Feb 2003 11:58:25 -0800

John,

When you create an object with alloc/init, the -retain message is redundant.

See Malcolm Crawford's article, "Very simple rules for memory management in Cocoa" here:

http://www.stepwise.com/Articles/Technical/2001-03-11.01.html

And Don Yactman's "Hold me, use me, free me" at:

http://www.stepwise.com/Articles/Technical/HoldMe.html

On Thursday, February 20, 2003, at 08:07 PM, John Timmer wrote:

Greetings -

I've got a program on an NSTimer that repeats every 5 minutes or so between
checking something and (potentially) grabbing an image from a server. If I
set it up so it repeats quickly and always grabs the image, it's clear it's
leaking memory. Using "leaks" indicates that a lot of it is in the form of
NSImages. I've tried a bunch of variations on the following code, but
either I leak or I tank because I try to release something that no longer
exists. Any advice is appreciated.

NSData *imageData = [[[ NSData alloc] initWithContentsOfURL: theURL
]autorelease];

NSImage *tempImage = [[NSImage alloc] initWithData:imageData];
// this bit simply prevents the background from blowing holes in
wherever it's composited
[weatherImage release];
weatherImage = [[[NSImage alloc] initWithSize:[tempImage size]] retain];
[weatherImage lockFocus];
[tempImage compositeToPoint:NSMakePoint(0,
0)operation:NSCompositeSourceOver];
[weatherImage unlockFocus];
[tempImage release];

I do the compositing in a different method, but I don't create any images
there.

By the way, I'm leaking something else, too - in some archives, I've seen
that NSURL leaks - is this still the case, or should I look elsewhere?

Cheers,

John
_______________________________________________
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.


John C. Randolph <email@hidden> (408) 974-8819
Sr. Cocoa Software Engineer,
Apple Worldwide Developer Relations
http://developer.apple.com/cocoa/index.html
_______________________________________________
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.

References: 
 >Leaking images (From: John Timmer <email@hidden>)

  • Prev by Date: Re: http://127.0.0.1 in Safari goes to nameserver?
  • Next by Date: NSTableView - problem with drawing cell text
  • Previous by thread: Re: Leaking images
  • Next by thread: Re: Application Security...
  • Index(es):
    • Date
    • Thread