discuss-gnustep
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: NSViewController; loading views from nibs


From: Fred Kiefer
Subject: Re: NSViewController; loading views from nibs
Date: Tue, 19 Apr 2011 00:06:23 +0200
User-agent: Mozilla/5.0 (X11; U; Linux x86_64; de; rv:1.9.2.14) Gecko/20110221 SUSE/3.1.8 Thunderbird/3.1.8

On 15.04.2011 22:05, Ivan Vučica wrote:
On Mon, Jan 24, 2011 at 12:44, Fred Kiefer<fredkiefer@gmx.de>  wrote:


I read a bit of Apple docs and figured out how loading from nibs is done.
I
added support in Zcode, and  prepared a patch for GNUstep GUI. It's
clumsy
but works for my needs.

I submitted a patch similar to yours. This class will still need some
work to be truly useful.


Hi Fred,

It seems to me that your implementation of NSViewController's -loadView
(which I tested only now) has a bug with retaincount. I never took a deep
look at what NSNib is doing, but it seems to me that nib being released at
the end of loadView pulls all other objects with it. That's just my guess.

This bug is manifesting in Zcode. I have NSViewController subclasses for the
editor, which are unloaded upon file switch and replaced with a different
NSViewController. All of them are defined in nibs.

Program crashes when I release the old subclass of NSViewController. The
crash occurs in NSViewController's release, when _topObjects is released.

This problem did not occur with my original submitted patch, which has used
the same method that is used in NSWindowController's -loadWindow. Zcode used
this method for a while, and it seems ok to me. Zcode also runs under Cocoa,
so I guess I am Doing Things Right(tm).

Here is a patch that uses the same method that I used in Zcode. It fixes the
crash and exposes -loadView publicly (which I think is ok, since people who
subclass NSViewController should know that -loadView exists).

Please tell me if I introduced a memory leak; I don't know exactly what I'm
doing and basically I'm learning from NSWindowController's source code.

Sorry, only today did I find this mail plus a lot more from you in my spam folder. Don't know why GMX put them there, but it hopefully explains why I didn't reply before.

You are definitely correct about the loadView method. It should be exported in the header file, probably that's why I added it there three months ago :-) Looks like your header files don't match the implementation files as the later one seems up to date.

As for the NIB loading code, the method used in the current GNUstep code and the one that you suggest should be almost identical in the result. (Ignoring that your code will only load NIBs from the main bundle, that would be easily fixed) If the current method results in a segmentation fault then we have a real problem here and just not just ignore it by using a different interface. Is the ZCode application freely available and how would I reproduce the problem with that code? Most likely the problem has to do with topLevelObjects, but I cannot see the bug at the moment. Maybe it is that I wrote most of the code myself that keeps me from spotting the obvious. Anybody with a bit more insight out there? Ah, I think finally I see it, topLevelObjects gets set to an autoreleased array and later the NSViewController releases it in its dealloc method. We should have retained it after the NIB loading!
I will try to correct this.

Fred



reply via email to

[Prev in Thread] Current Thread [Next in Thread]