NSMovie and DisposeMovie
NSMovie and DisposeMovie
- Subject: NSMovie and DisposeMovie
- From: Des Courtney <email@hidden>
- Date: Wed, 18 May 2005 10:54:39 -0500
Okay, this is my first post to this particular mailing list, so I'm
not sure if I can communicate my problem correctly. I come from
a mostly C/C++ background, and I have only been doing work under
Objective-C/Java for a few weeks.
As an experiment to learn Cocoa, I've been making an app that rapidly
plays NSMovies via differing NSMovieViews. (Yes, I'll ask about
QTKit in a bit; I haven't upgraded to QT 7 yet.) Since it's
possible for different NSMovieViews to play the same NSMovie, I
made a subclass of NSMovieView to create an internal [NSMovie copy]
so that any play status changes to an individual movie don't
bleed to other views. I then call [NSMovie release] on the internal
copy before accepting a new NSMovie, so as to balance the ref counts.
For the record, the movies being assigned to the views are stored
in a "master" NSDictionary outside of the movie views; these movies
are originally loaded in via [NSMovie initWithURL:byReference:].
I left this app running for over an hour, and noticed some performance
slowdown; so I ran it through ObjectAlloc and discovered that
each of my movie copies were leaking about dozen or so
"libSystem.B.dylib" memory allocations. I made a contrived example
to isolate the problem...
// Instance variables NSMovie myRefMovie and NSTimer myTimer
// in an Interface Builder instantiated class
- (void) awakeFromNib {
// Fetch a file path to a movie and convert it to a NSURL "theURL"
myRefMovie = [[NSMovie alloc] initWithURL:theURL byReference:YES];
myTimer = [[NSTimer scheduledTimerWithTimeInterval:1.0
target:self selector:@selector(reactToTimer:)
userInfo:nil repeats:YES] retain];
} // awakeFromNib
- (void) reactToTimer:(NSTimer*)inTrigger {
NSMovie* theClone;
theClone = [myRefMovie copy];
[theClone release]; // Why does this leak?
} // reactToTimer:
The above exaggerates the movie copying; my experimental app
doesn't create and destroy copies nearly so much...
I was able to fix the leak after double-checking Apple's docs
for this class and suspecting that the [copy] movies were
internally init'ed via [NSMovie initWithMovie:]. I added
code similar to "DisposeMovie([NSMovie QTMovie])" (which the
docs say I'm NOT supposed to do), and ObjectAlloc confirmed the
plugged leak.
Finally, my questions:
A) Should I regard this as a bug or feature? Having initWithMovie:
NOT auto-dispose makes some sense, but using the NSCopying
protocol method shouldn't inherit this behavior, methinks...
B) Can anybody out there try this same code with QTMovie (or
what ever QTKit calls the class)? I'm still using Panther
here, and I've heard some bad things about trying to use
QuickTime 7 on pre-Tiger systems. I'd like to know if this
memory leaking behavior is still present.
Des
--
Des Courtney - Mascon Global, Ltd.
Computer Programmer - Macintosh Specialist
<mailto:email@hidden>
_______________________________________________
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