Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Native Development

Reply
bbj
Contributor
bbj
Posts: 43
Registered: ‎02-22-2012
My Device: Developer
My Carrier: Various
Accepted Solution

Modeless SystemDialogs = when do you 'delete' them ?

 

If you use the SystemDialog::show method to display the System dialog as a modeless dialog where/when do you actually 'delete' the created SystemDialog + thus free the memory it was using.

 

In the SystemDialog:::exec() case you can simply delete the dialog once the exec() returns. But clearly you cant do that with  a modeless dialog.

 

As far as we can see its really unsafe to assume you can delete the dialog in the finished() signal, not least of which its almost certainly still executing code + thus probably manipulating object property.

Please use plain text.
Developer
peter9477
Posts: 6,473
Registered: ‎12-08-2010
My Device: PlayBook, Z10
My Carrier: none

Re: Modeless SystemDialogs = when do you 'delete' them ?

It may interest you to know that the system dialogs are implemented using a separate OS service, which runs in its own process and with separate resources, etc. When you're not displaying one of them, I doubt they use up any resources which should concern you.

If you're asking about deleting the local objects which track the connection to that service, for one thing I doubt they consume much memory either, since they should just contain enough to hold the various parameters you've defined. For another thing, if you don't plan to use them to display the dialog again, I'm pretty sure you could delete them whenever you want, unless the docs explicitly say you should not.

Peter Hansen -- (BB10 and dev-related blog posts at http://peterhansen.ca.)
Author of White Noise and Battery Guru for BB10 and for PlayBook | Get more from your battery!
Please use plain text.
bbj
Contributor
bbj
Posts: 43
Registered: ‎02-22-2012
My Device: Developer
My Carrier: Various

Re: Modeless SystemDialogs = when do you 'delete' them ?

Not sure we really understand your response.

 

A memory leak is a memory leak regardless of size. Eventually it will use ALL the memory on your device/allocated to your process + invariably cause problems. Granted it may take a while if its only a few bytes, but thats not really the point.

 

By definition when a modeless dialog is being displayed your app is also running. Clearly you cannot just simply delete resources used by the modeless dialog (or the dialog object itself) at any random point during the running of the app and still expect the dialog to be displayed correctly + deliver its finished signal. 

 

Regardless of whether the implmentation of system dialogs is in a separate OS service/thread/process or whatever at a minimum you must be deleting any linkages back to your app if you delete the SystemDialog object created in your local heap space and to which you connected a method to its finished signal.

 

Generally deleting an object within one of its own methods (or callbacks) or in this case a 'signal/slot pairing' results in memory corruption UNLESS the object is very explictly coded to deal with 'self deletion' and any environment its running in can handle that object being removed while in the middle of some of its methods being accessed. 

 

With respect, the docs are lacking in quite a few areas, plain wrong in others + simply non existant in quite a few areas.  There is nothing in the docs that suggest you should ever delete a SystemDialog created e.g. using std code such as

 

SystemDialog* dlg = new SystemDialog("title");

 

but if you dont you have a memory leak - you can see it happening in the Malloc Info panes of the IDE.

 

So the question stands, where are you expected to delete the SystemDialog object thats created in your local heap space when its run as a modeless dialog

 

 

 

Please use plain text.
bbj
Contributor
bbj
Posts: 43
Registered: ‎02-22-2012
My Device: Developer
My Carrier: Various

Re: Modeless SystemDialogs = when do you 'delete' them ?

If relevant to people:

 

Now the documentation has been updated there is a method called 'deleteLater()' which apparently is safe to call when in the finished slot - presumably it runs some kind of deferred pseudo garbage collector...

 

 

Please use plain text.