OldBoy Posted November 14, 2013 Report Share Posted November 14, 2013 Working in a project which based in the Factory Pattern,we wanted to remove the child classes from memory as they were too heavy. I had always read that it seemed to be no way to do it. After trying different ideas, I came out with one that spins around of the use of a queue where the data is a class. For this example I used the ‘LV Object’, just trying to do my code the most generic as possible. When I launch my factory, the code does the following: - Obtains a new one element size queue with a LV Object constant as element data type - Loads the child using the factory - Enqueues the new child in the queue using the function 'Lossy queue element'. Obviously, at that moment I had my child in memory, but I discovered that once I released the queue, the child vanished as well from the LV hierarchy, allowing me to load a new child in case I needed, using the factory pattern again. You can find the code attached with the post. As I said I read some posts saying that is not possible to remove the child classes from memory, but this seems to work and I would like to know your opinion, as not being able to run the class hierarchy chart when I run compiled code I cannot ensure that this solution behaves as it seems, although it doesn’t create any errors either. Thanks for your help and time P.S I attach a video where you can see the behaviour of the example Quote Link to comment
drjdpowell Posted November 14, 2013 Report Share Posted November 14, 2013 Try adding a method to your child classes. That seems to make them stay under “Dependancies>>items in memory”. Quote Link to comment
OldBoy Posted November 14, 2013 Author Report Share Posted November 14, 2013 I have tried your idea. You are right. Thank very much indeed for your time and help. Quote Link to comment
unicorn Posted November 14, 2013 Report Share Posted November 14, 2013 I think to remember that there is some description by NI that classes are loaded and unloaded if not used any more. I would expect the runtime engine to behave in the same way as the development environment. So if you see a class to be unloaded in the development Environment using the LabVIEW class hierarchy window the same should happen with compiled code. Quote Link to comment
JPina Posted November 14, 2013 Report Share Posted November 14, 2013 I think to remember that there is some description by NI that classes are loaded and unloaded if not used any more. I would expect the runtime engine to behave in the same way as the development environment. So if you see a class to be unloaded in the development Environment using the LabVIEW class hierarchy window the same should happen with compiled code. I'd appreciate if you could you tell me where can I find that document. Thank you Quote Link to comment
unicorn Posted November 15, 2013 Report Share Posted November 15, 2013 I would have added the link if I would have remembered. Quote Link to comment
shoneill Posted November 15, 2013 Report Share Posted November 15, 2013 When I launch my factory, the code does the following: - Obtains a new one element size queue with a LV Object constant as element data type - Loads the child using the factory - Enqueues the new child in the queue using the function 'Lossy queue element'. Obviously, at that moment I had my child in memory, but I discovered that once I released the queue, the child vanished as well from the LV hierarchy, allowing me to load a new child in case I needed, using the factory pattern again. You can find the code attached with the post. That's really cool, I did not know that removing a loaded class was possible.... Must remember this. Quote Link to comment
JPina Posted November 15, 2013 Report Share Posted November 15, 2013 That's really cool, I did not know that removing a loaded class was possible.... Must remember this. Actually it is not possible, drjdpowell knocked down the theory... Quote Link to comment
Michael Aivaliotis Posted November 15, 2013 Report Share Posted November 15, 2013 Actually it is not possible, drjdpowell knocked down the theory... Agreed. Once a class is loaded into memory, it cannot be unloaded. LabVIEW class factory pattern Quote Link to comment
unicorn Posted November 22, 2013 Report Share Posted November 22, 2013 But if you open the class hierarchy window and you can see classes appearing and disappearing, there must be a process to unload classes as well. You cannot force LV manually to unload a class Quote Link to comment
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.