Professional Web Applications Themes

[NSWindowController] dealloc is not called - Mac Programming

Hello, I have a doent-based cocoa program with a own NSWindowController called MainWndCtrl Of course I implemented in the MyDoent the - (void)makeWindowControllers { MainWndCtrl *mainWndCtrl = [[MainWndCtrl alloc] init]; [self addWindowController:mainWndCtrl]; [mainWndCtrl release]; } In IB I set the file's owner custom class to the MainWndCtrl. So the init-method in the MainWndCtrl is called: - (id)init { NSNotificationCenter * nc; if(self = [super initWithWindowNibName:"MyDoent"]) { [self setWindowFrameAutosaveName:"RWKi3D"]; nc = [NSNotificationCenter defaultCenter]; [nc addObserver:self selector:selector(handleUpdateUI:) name:UPDATEUI object:nil]; } return self; } But I have one problem. The dealloc-method is not called: -(void)dealloc { NSLog("dealloc"); [myTimer release]; NSNotificationCenter * nc; nc ...

Sponsored Links
  1. #1

    Default [NSWindowController] dealloc is not called

    Hello,

    I have a doent-based cocoa program with a own NSWindowController
    called MainWndCtrl

    Of course I implemented in the MyDoent the
    - (void)makeWindowControllers
    {
    MainWndCtrl *mainWndCtrl = [[MainWndCtrl alloc] init];
    [self addWindowController:mainWndCtrl];
    [mainWndCtrl release];
    }

    In IB I set the file's owner custom class to the MainWndCtrl.

    So the init-method in the MainWndCtrl is called:

    - (id)init
    {
    NSNotificationCenter * nc;

    if(self = [super initWithWindowNibName:"MyDoent"]) {
    [self setWindowFrameAutosaveName:"RWKi3D"];

    nc = [NSNotificationCenter defaultCenter];
    [nc addObserver:self
    selector:selector(handleUpdateUI:)
    name:UPDATEUI
    object:nil];
    }

    return self;
    }

    But I have one problem. The dealloc-method is not called:

    -(void)dealloc
    {
    NSLog("dealloc");

    [myTimer release];

    NSNotificationCenter * nc;
    nc = [NSNotificationCenter defaultCenter];
    [nc removeObserver:self];

    [super dealloc];
    }

    I do not see why dealloc is not called. Why it is not called?

    Bye and thanks - Robert
    Sponsored Links
    Robert Guest

  2. #2

    Default Re: [NSWindowController] dealloc is not called

    Robert W. Kuhn <de> wrote:

    [NSwindowController] 

    I found the cause. I have a NSTimer in the WindowController.
    I start the timer in windowDidLoad:

    - (void)windowDidLoad
    {
    //Timer starten
    myTimer = [[NSTimer scheduledTimerWithTimeInterval:0.25
    target:self
    selector:selector(onTimer:)
    userInfo:nil
    repeats:YES] retain];

    When I start the timer dealloc is not called. But when I do not start
    the timer (comment out the code) dealloc is getting called. What's this?
    How can I work around this problem?

    Thanks and bye - Robert
    Robert Guest

  3. #3

    Default Re: [NSWindowController] dealloc is not called

    Robert W. Kuhn <de> wrote:
     

    dealloc is called when an instance is destroyed (there are no more
    retains on it). So if dealloc is not called it is because the instance
    is not being destroyed. You don't show any code that would explain under
    what cirstances you expect the instance to be destroyed, so there's
    no more to say, is there? m.


    --
    matt neuburg, phd = com, http://www.tidbits.com/matt/
    AppleScript: The Definitive Guide
    http://www.amazon.com/exec/obidos/ASIN/0596005571/somethingsbymatt
    Read TidBITS! It's free and smart. http://www.tidbits.com
    matt Guest

  4. #4

    Default Re: [NSWindowController] dealloc is not called

    Robert W. Kuhn <de> wrote:
     
    >
    > I found the cause. I have a NSTimer in the WindowController.
    > I start the timer in windowDidLoad:
    >
    > - (void)windowDidLoad
    > {
    > //Timer starten
    > myTimer = [[NSTimer scheduledTimerWithTimeInterval:0.25
    > target:self
    > selector:selector(onTimer:)
    > userInfo:nil
    > repeats:YES] retain];
    >
    > When I start the timer dealloc is not called. But when I do not start
    > the timer (comment out the code) dealloc is getting called. What's this?[/ref]

    Perhaps target:self retains the instance so it is not destroyed. And a
    good thing too, since otherwise when the Timer fires the application
    will crash. m.

    --
    matt neuburg, phd = com, http://www.tidbits.com/matt/
    AppleScript: The Definitive Guide
    http://www.amazon.com/exec/obidos/ASIN/0596005571/somethingsbymatt
    Read TidBITS! It's free and smart. http://www.tidbits.com
    matt Guest

  5. #5

    Default Re: [NSWindowController] dealloc is not called

    matt neuburg <com> wrote:
     

    It was a NSTimer who retains the controller. Now I do a

    - (void)windowWillClose:(NSNotification *)aNotification
    {
    [myTimer invalidate];
    [myTimer release];
    }

    and everything is :-)
    Robert Guest

  6. #6

    Default Re: [NSWindowController] dealloc is not called

    Robert W. Kuhn <de> wrote:

    [NSwindowController] 

    I found the cause. I have a NSTimer in the WindowController.
    I start the timer in windowDidLoad:

    - (void)windowDidLoad
    {
    //Timer starten
    myTimer = [[NSTimer scheduledTimerWithTimeInterval:0.25
    target:self
    selector:selector(onTimer:)
    userInfo:nil
    repeats:YES] retain];

    When I start the timer dealloc is not called. But when I do not start
    A

    - (void)windowWillClose:(NSNotification *)aNotification
    {
    [myTimer invalidate];
    [myTimer release];
    }

    solves the problem.

    Thanks and bye - Robert
    Robert Guest

  7. #7

    Default Re: [NSWindowController] dealloc is not called

    Robert W. Kuhn <de> wrote:
     
    >
    > I found the cause. I have a NSTimer in the WindowController.
    > I start the timer in windowDidLoad:
    >
    > - (void)windowDidLoad
    > {
    > //Timer starten
    > myTimer = [[NSTimer scheduledTimerWithTimeInterval:0.25
    > target:self
    > selector:selector(onTimer:)
    > userInfo:nil
    > repeats:YES] retain];
    >
    > When I start the timer dealloc is not called. But when I do not start
    > A
    >
    > - (void)windowWillClose:(NSNotification *)aNotification
    > {
    > [myTimer invalidate];
    > [myTimer release];
    > }
    >
    > solves the problem.[/ref]

    Might it help in general to spend more time thinking and less time
    posting? m.

    --
    matt neuburg, phd = com, http://www.tidbits.com/matt/
    AppleScript: The Definitive Guide
    http://www.amazon.com/exec/obidos/ASIN/0596005571/somethingsbymatt
    Read TidBITS! It's free and smart. http://www.tidbits.com
    matt Guest

  8. #8

    Default Re: [NSWindowController] dealloc is not called

    matt neuburg <com> wrote:
     

    Isn't it the same?

    Robert
    Robert Guest

Similar Threads

  1. Replies: 8
    Last Post: December 19th, 03:08 PM
  2. Replies: 0
    Last Post: November 29th, 10:21 AM
  3. Replies: 0
    Last Post: November 29th, 10:03 AM
  4. [Q] Why unsolicited dealloc in NSKeyedUnarchiver?
    By Peter in forum Mac Programming
    Replies: 6
    Last Post: April 23rd, 08:13 PM
  5. NSWindowController - new instance ?
    By Florian in forum Mac Programming
    Replies: 3
    Last Post: April 20th, 06:11 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139