Re: Object allocation problem
Re: Object allocation problem
- Subject: Re: Object allocation problem
- From: Paul Lynch <email@hidden>
- Date: Fri, 17 Mar 2006 15:33:51 +0000
On 17 Mar 2006, at 15:28, Valerio Ferrucci wrote:
Hi,
perhaps I didn't understand very well the object allocation/
deallocation.
I want the poster from a movie to display in myApp.
That seems to be the problem.
BUT
If I uncomment the "[mov release]" line in the following code my
App crashes.
Can someone explain me why?
How can I fix this?
- (NSImage*)getMoviePoster:(NSString*)moviePath
{
NSError *openError = nil;
QTMovie *mov = [QTMovie movieWithURL:[NSURL
fileURLWithPath:moviePath] error:&openError];
NSImage *poster = [[mov posterImage] copy];
// [mov release];
return poster;
}
movieWithURL:error: returns an autoreleased object (the docs don't
say so, but this is by naming convention).
The convention is that you should release objects that you have alloc/
init, or autorelease them if returned. Class methods starting with
the class name (or a version of it) are always returned autoreleased.
Exercise for the reader: you might want to check what the status is
of your poster return value.
Paul
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden