679 views
in System Integration by
Hi there,

i setup a timer that fires once a second and prints out the value of a property i had setup in Application::Device. The property is called myName which is a string that defaults to "Undefined". From my main Application i set the timer to set the myName Variable to "Name" whenever it is "Undefined". When running this code from the Prototyper i can see that the myName variable gets set correctly, and then gets reset somehow every perceived 8-12 seconds. Why is that? My Debug Log looks like this:

trace: "Undefined"
trace: "Name"
trace: "Name"
trace: "Name"
--- some more seconds pass ---
trace: "Undefined"
trace: "Name"
trace: "Name"

How comes the variable/property looses its state and seemingly gets reinstantiated?

best regards!

1 Answer

0 votes
by
 
Best answer

Hello,

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.

I assume that your Application::Device class is accessed as autoobject in your application.

Please consider the livetime 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. 

I hope this helps....

Best regards,

Manfred.

by
Hello there,

thanks for the explanation; adding the variable the way you described indeed 'solved' the issue i had.

Thanks!

Ask Embedded Wizard - Archive

Welcome to the Ask Embedded Wizard archive. This community forum served us well for many years, but we've evolved our support approach!

Your resources:

The Embedded Wizard Online Documentation provides comprehensive documentation, tutorials, examples and ready-to-use software packages.

For dedicated assistance, explore our Embedded Wizard Product Support.

You can still browse the valuable discussions from our community history here.

Embedded Wizard Website | Privacy Policy | Imprint

...