• 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
NSMovie and DisposeMovie
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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


  • Prev by Date: Re: Can NSCell draw both an icon and text?
  • Next by Date: Re: CoreData issue when updating a file format
  • Previous by thread: Handling a Null PlaceHolder on a Bound PopUp (with CoreData)
  • Next by thread: Re: NSMovie and DisposeMovie
  • Index(es):
    • Date
    • Thread