92 views
in GUI Development by
Hello, I can't figure out how to perform the following sequence of actions:
1. I create a screen and display information on it.
2. A certain event occurs.
3. I need to destroy the current screen and build a new one instead, i.e. the same class, only with different content.

The problem is with point 3. I need to not just overlap or hide it, but rather destroy it, since there can be many such events and I will have a memory leak if screens are simply created on the stack and overlapped.

1 Answer

0 votes
by

Hello Aleksey,

the answer to your question depends on how you present the screen. If you used Add() method to display it, use its counterpart Remove(). See also Compose the component programmatically. If the screen was presented as dialog using e.g, PresentDialog() use its counterpart DismissDialog(). See also Managing dialogs (multiple screens).

The destroy operation itself is not existing in Embedded Wizard. Objects which are not in use anymore are automatically discarded during the next garbage collection cycle. See also Deinitialization.

Best regards

Paul Banach

by
Thanks for your answer, Paul! For complete understanding one more example:

var MyScreen dialog = new MyScreen;
PresentDialog(dialog, .... );
some work here;
DismissDialog(dialog, ....);
dialog = new MyScreen;

I can be sure that after calling DismissDialog() the first screen object will not be on the screens stack and will then be garbage collected, right?
by

Hello Aleksey,

I can be sure that after calling DismissDialog() the first screen object will not be on the screens stack and will then be garbage collected, right?

Let me explain the functionality more in detail.

DismissDialog() limits to schedule the affected dialog to be hidden and removed from the view tree (eventually with an animation if such has been configured in the parameters of PresentDialog() or DismissDialog()). The scheduled operation is performed with a short delay. That means, when the invocation of DismissDialog() returns, the object is still existing.

The object disposal is performed during the next garbage collection. In target system the garbage collection is triggered at the end of each screen update. In other words, the dismissed dialog will occupy RAM until the current screen update has been finished. Or if the operation is performed with animation, after the screen update of the last animation phase is done.

The disposal, however, can be suppressed if there is any variable in your GUI still referring the object of the dialog, or referring one of objects embedded inside it. Through such 'strong' reference the object in question remains accessible and garbage collection can't delete it.

If you worry about the RAM usage, you can track it at the prototyping time via the Memory (RAM usage window. This gives you a rough estimation. For more precise results you can monitor the memory usage in target system. Both approaches are very useful if you have the impression of increasing memory consumption due to e.g. growing chains of objects.

Best regards

Paul

by
Paul, thanks for your help!

Embedded Wizard Website | Privacy Policy | Imprint

...