Class Member Variables / Garbage Collection

Recommended Posts

I have recently started using DAQFactory and am really enjoying the flexibility it offers, particularly with a Win32 and C/C++ background.


I have a question about garbage collection with class objects (during development).  I realize OOP is officially undocumented, but ToJson/FromJson methods are really a great motivation to use it for at least storage of application settings.


I create a sequence defining a class containing various member variables.  After running the sequence to compile the class, I construct a new() instance for a global variable.  All works well and ToJson()/FromJson() operate on the global instance as expected.  However, if I subtract unwanted members from the class, re-run the sequence, and re-new() the global, the resulting object still contains all the old member variables (i.e. via ToJson() on the object).  Likewise, if I rename variables, the resulting object will be a union of the original variables and the renamed variables.  I have tried ClearGlobals() without success.


Other than reloading the application in DaqFactory, is there a way to 'clear' a compiled class structure during development (i.e. some operation like ClearObjects(), _ClassName.class=, etc.)?  I am using ToJson() to build configuration files and I noticed many unnecessary entries being written after I update/change my settings class.


Thank you for your time with this simple query.

Link to comment
Share on other sites

No, there is no way to clear them out without restarting.  Just save your doc and restart.  Its largely a side-effect of the ability to change classes on the fly, which works quite well when you are changing member functions.  You just rerun the sequence with your class declaration, and all instantiated instances of the class are updated with the changes (of course if a sequence is calling into that member function at the time, it will need to exit and come back in for the changes to be seen).  However, with member variables its different.  If you add member variables, they won't appear in already instantiated classes.  


I suppose I should explain how DAQFactory does its OOP and then it will make more sense.  Because of the dynamic nature of DAQFactory, its not done the same way as C++ or other truly compiled languages.  What happens is when you create a class, DAQFactory stores all the functions and all the member variables internally in an object. With any initialization (i.e. local myVar = 4), the initialized value is also stored.  Then when you instantiate an object of the class, it copies all the member variables into the instantiated object, but only stores the class name for the functions.  When you access member variables of the object you get the variables that were copied, but if you access member functions, DAQFactory looks to the class itself.  That's why changes to functions carry to all objects, but not variables.  


Now when you modify an existing class, it doesn't rebuild it from scratch.  Instead it adds or modifies the existing class.  This results in orphan variables and functions until you restart DAQFactory.  It really isn't a problem, except when you use toJson().  


I'm going to move this to feature requests and we'll look to either adding a clearObjects() or do some other sort of cleanup.

Link to comment
Share on other sites

Thanks for the internal details...I respect the balance you had to make to support the dynamic qualities of the language.  The workaround is only a minor issue and toJson() is worth it.  As a side note, as a new forum member, I am amazed by your quick and detailed reply...and on a weekend too!  Exceptional customer service...thank you.

Link to comment
Share on other sites


This topic is now archived and is closed to further replies.