• 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: NSWindow's setContentView
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: NSWindow's setContentView


  • Subject: Re: NSWindow's setContentView
  • From: Shawn Erickson <email@hidden>
  • Date: Sun, 18 Jun 2006 20:22:30 -0700


On Jun 18, 2006, at 8:02 PM, Drarok Ithaqua wrote:

For sake of simplicity, let's assume I want to swap the contents of two windows, mainWindow and playlistWindow.

mainWindow contains an NSMovieView, and playlistWindow contains only an NSTableView. I run the following code:


NSView* playView = [playlistWindow contentView];
NSView* mainView = [mainWindow contentView];

// Assuming retainCount of 1 on both views to start with...
NSLog( @"main: %d. play: %d", [mainView retainCount], [playView retainCount] );


[playView retain]; // (2)
[mainView retain]; // (2)

[playlistWindow setContentView:mainView]; // playView gets a release(1), mainView a retain(3)
[mainWindow setContentView:playView]; // mainView gets a release (2), playView gets a retain(2).

[mainView release]; // (1)
[playView release]; // (1)

NSLog( @"main: %d. play: %d", [mainView retainCount], [playView retainCount] );


Debug says this:
2006-06-19 03:59:37.103 Flix[28513] main: 1. play: 1
2006-06-19 03:59:37.126 Flix[28513] main: 2. play: 2

And then, if I call that code again, I get a crash.
I'm assuming some autoreleasing is going on, but I really don't understand why the retainCounts are 2 when I think they should only be 1...

Actually setContentView likely sends an autorelease message instead of a release message to the one it is replacing.


Looking at retain counts can easily confuse since things like autorelease don't get counted until some time in the future.

-Shawn
_______________________________________________
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


References: 
 >NSWindow's setContentView (From: Drarok Ithaqua <email@hidden>)

  • Prev by Date: NSWindow's setContentView
  • Next by Date: NSTableView controlTextDidChange:
  • Previous by thread: NSWindow's setContentView
  • Next by thread: NSTableView controlTextDidChange:
  • Index(es):
    • Date
    • Thread