Jump to content

Factory pattern: delete child class from memory


Recommended Posts

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

Link to comment

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.

Link to comment
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 ;)

Link to comment

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. :worshippy:

Link to comment

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.