Posts

Posts mit dem Label "ARC" werden angezeigt.

WebView and ARC

Another ARC related note in my blog and as I can see a problem that maybe a couple of other coders have faced as well. I am using a custom WindowController to handle a WebView and some javascript to interact with a web page. When closing the window, the window controller should get closed. Yet, its dealloc method doesn't get called. After some digging I found out that javascript calls via the windowScriptObject block the release of the web view and thus of the window controller. Setting the value for my scripting key to nil was one solution. Yet, as soon as I called javascript functions with parameters from my windows controller, the dealloc was blocked again. Loading an empty string in the mainFrame of the WebView as soon as the window will close solved that for me. So, ARC and WebView seem to play nicely together

ARC, NSWindowController and NSDocument

For bcAdmin 3 I decided to give ARC a try and use it. For a large project like bcAdmin 3 that was a big step, and I wasn't sure in the beginning, if it was the way to go. Now and then I stumble over problems, most/all of these I could solve so far. One current one was the creation of NSWindowControllers for displaying informations in extra windows. Before ARC I was storing these in local variables of my document and was releasing them when possible or necessary. This needed some glue code I didn't like. Then I stumbled over NSDocument's -addWindowController: - which I missed completely the years before. First try was to create a local instance of my window controller, add it via the above method and when closing the window, I expected it to dealloc. It didn't... the trick was here to declare the local variable as __autoreleasing ... and now it works as expected.