246 views
in Embedded Wizard Studio by

Hi,

I found something strange, consider a simple program like the picture below, what it does is 

  1. In Init function, it set the value of a property to 100 (default is 3)
  2. Print the value of the property every second

When I start prototyping this component, it gives out the correct value 100 at the begaining, but after couple seconds, the value reset to 3.

Why is that happending?

 

1 Answer

+1 vote
by
 
Best answer

Hello John,

I assume the property that you are accessing from time to time is stored within a device class. Typically, a device class is handled as an autoobject in order to have one global instance of the device class. This is very convenient, because autoobjects can be accessed from everywhere in your project.

Please consider the lifetime of autoobjects. Everytime, the autoobject is no more in use, the instance will be deleted by the Garbage Collector. When the timer expires, a new instance of the device class will be created. Within the Prototyper on PC, the Garabage Collector is running after a couple of seconds - this explains, why you get sometimes the expected value and why the content is lost after some seconds. 

In order to prevent the Garbage Collector from freeing an autoobject, please add a variable to the root class, set the type to your class Application::Device and the value to the instance (autoobject) of the class. 

Does this answer your question?

Best regards,

Manfred.

 

by
Hi Manfred,

Yes, it solves the problem ,thank you!

Ask Embedded Wizard

Welcome to the question and answer site for Embedded Wizard users and UI developers.

Ask your question and receive answers from the Embedded Wizard support team or from other members of the community!

Embedded Wizard Website | Privacy Policy | Imprint

...