Archive for the ‘Cocoa’ Category

Xcode and 64 bit apps on Leopard? A small step still remains…

Friday, September 26th, 2008

Although Xcode is the only real world 64-bit application on Leopard, it is not yet fully dedicated to support the 64-bit applications on 100%. It has still major defects using debugger at 64-bit applications. I tried to make one my application 64-bit, but the debugger stopped me from doing it so, and I switched back to 32-bits during the development. However, I plan to get back to 64-bits later, I’m not giving up though… [-;


This is how debugging should look like

At first, I started wandering where did my objective-c variables go. I thought I hadn’t have switched on some build variable, so I was looking for some magic check box, but without any luck. After some searching, and experimenting, I found that when the application was running at 32-bit mode, everything was just fine, but when I switched back to 64-bit mode, all the variables went away. At the same time, I also found that gdb doesn’t allow me to execute any objective-c methods. This might be the reason why no variables were shown. This also sucks, since I call obj-c variables quite often as I need to display value of some object, or test something.


And this is how it is in 64-bits.

I don’t know what is the cause of this. It is apparently some change in the obj-c runtime system that broke the things. I don’t even know whether this worked at previous Xcode version (I used 3.1 now), so it might be just a bug, but quite annoying.

Leopard is a good start on the 64-bits way, but Apple has still long way to go if they want us to use and develop 64-bits as the main job. I hope that Snow Leopard will continue the current effort in computing to bring the real 64-bit environment.

Releasing NSWindowController properly

Saturday, September 20th, 2008

Yesterday I found that one my application doesn’t release NSWindowController. The problem was that I was not using NSDocument architecture, and releasing NSWindowController is a little different without NSDocument than with NSDocument.

By default, when closing a window with the red button on the top, you will not release the window controller object. If you want to do so, you must implement the windowWillClose notification in your window controller, and autorelease self. Yes, autorelease self, because this will release window controller later after the code that handles the click on the red button handles to the close event, and hides the window. During all this work, the window controller must be ready to react. Later, when your window controller gets disposed, it also automatically decreases retain count in the window, and thus the window object will be released as well. So you should use code such as this in your NSWindowController subclass:

@implementation MyWindowController
-(void) windowWillClose:(NSNotification *)notification
{
   [self autorelease];
}

Also don’t forget that your window cannot have two properties that automatically release some objects. Both must be set to FALSE. The first property releases the document on close of window (your application would crash if set to TRUE - there is not document - hm, Apple might check this as well, and not to crash the application). The second property is that the window itself will be released on close (your application would also crash since the window will release itself, and your controller will do the same later, so the release count will be 0 at the time of the second release). This second property is often set in Interface Builder application. So, consider calling these two functions when creating a new window.

[[myWinController window] setReleasedWhenClosed:FALSE];
[myWinController setShouldCloseDocument:FALSE];