On Mon, Jan 24, 2011 at 12:44, Fred Kiefer <[email protected]> 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.
--
Ivan Vučica
[email protected]
Coming soon for iPhone, Zombie Ball - http://j.mp/zbivmail
Index: Source/NSViewController.m
===================================================================
--- Source/NSViewController.m (revision 32865)
+++ Source/NSViewController.m (working copy)
@@ -25,9 +25,12 @@
Boston, MA 02110-1301, USA.
*/
+#import <Foundation/NSBundle.h>
#import <Foundation/NSString.h>
+#import <Foundation/NSDictionary.h>
#import "AppKit/NSKeyValueBinding.h"
#import "AppKit/NSNib.h"
+#import "AppKit/NSNibLoading.h"
#import "AppKit/NSViewController.h"
@@ -96,30 +99,34 @@
- (void)loadView
{
- NSNib *nib;
+ NSDictionary *table;
+ NSString *nibPath;
if (_vcFlags.nib_is_loaded)
{
return;
}
- nib = [[NSNib alloc] initWithNibNamed: [self nibName]
- bundle: [self nibBundle]];
- if ((nib != nil) && [nib instantiateNibWithOwner: self
- topLevelObjects: &_topLevelObjects])
+ nibPath = [[NSBundle mainBundle] pathForNibResource: _nibName];
+
+ table = [NSDictionary dictionaryWithObject: self forKey: NSNibOwner];
+ if ([NSBundle loadNibFile: nibPath
+ externalNameTable: table
+ withZone: [self zone]])
{
+ // success!
_vcFlags.nib_is_loaded = YES;
- // FIXME: Need to resolve possible retain cycles here
+ // FIXME: Do we need to resolve possible retain cycles here?
}
else
{
if (_nibName != nil)
{
- NSLog(@"%@: could not load nib named %@.nib",
+ NSLog(@"%@: could not load nib named %@.nib",
[self class], _nibName);
}
}
- RELEASE(nib);
+
}
- (NSString *)nibName
Index: Headers/AppKit/NSViewController.h
===================================================================
--- Headers/AppKit/NSViewController.h (revision 32865)
+++ Headers/AppKit/NSViewController.h (working copy)
@@ -68,6 +68,8 @@
- (NSString *)nibName;
- (NSBundle *)nibBundle;
+- (void)loadView;
+
@end
#endif // OS_API_VERSION
_______________________________________________
Discuss-gnustep mailing list
[email protected]
http://lists.gnu.org/mailman/listinfo/discuss-gnustep