« Real Studio Developer… | Home | MBS Real Studio Plugi… »

Please don't call constructors outside new or constructor

Recently I saw code like this:

dim mytoolbar as new NSToolbarMBS
dim w as NSWindowMBS = window1.NSWindowMBS
w.toolbar = mytoolbar

mytoolbar.visible = true
mytoolbar.allowsUserCustomization = false

The plugin user asked why his code does not work. The reason is simply the calling of the Constructor a second time. The first time it is called in the new line. So in new we create an object in Realbasic from the plugin. The plugin creates in the default Constructor a dummy toolbar. This toolbar is now assigned to the window. Than in the second Constructor, we leak the first toolbar and create a new one. And this is that filled later with buttons.

So please only call constructor by new command or in your own constructors. This avoids trouble and memory leaks. The biggest plugin in space...
12 04 13 - 23:40