algorithmic modeling for Rhino
I'm writing a set of custom components of Grasshopper.
It seems that Grasshopper keeps the document and its related components when a document is closed.
The problem is, that some small windows (written by WPF) are created and used from my components. When a document is closed, it is just in a hidden state so the small windows remain.
My question is, how dose each component know its parent document is closed.
Is there some DocumentClosed() like event which is called when the document is closed?
Thanks.
Tags:
If you are creating those windows with the constructor, you could tap into the Dispose() method to destroy them. But in .Net your windows should be destroyed by the garbage collector once the component is destroyed.
..or is your window a global?
Thanks Hannes.
My windows are not global. They are members of my custom components.
Therefore, when the components are destroyed, the windows will be automatically destroyed.
The problem is, when a document is closed, the windows truly remain to be seen.
Then, I guess that closing a document is just a command that hide the document and thus the components are not destroyed and again, the windows are not destroyed.
If the components can know their parent document is closed, they can hide or destroy the windows manually.
Thanks.
Documents that are closed should eventually be garbage collected. If that's not the case it's a bug and I'll see if I can figure out whether that's happening. It could be that something is holding on to a pointer to the document and it could be me.
There will be a DocumentRemoved event on the Grasshopper.Instances.DocumentServer instance when a document is removed, so if you handle this event you can close all your windows associated with that document.
--
David Rutten
david@mcneel.com
Poprad, Slovakia
Hi David.
I did some experiments.
I wrote a custom component that has a WPF window and a Windows.Forms.Form as class members. They are not static members because if I place a new component, new windows appear. When I close the document, both WPF and Windows.forms windows stay in the screen.
I wait for more than thirty minutes because it is perhaps because of the delay of garbage collection. But they still stay in the screen.
This is why I guessed that the close document command just hide the document.
If this command truly destroys the document, I think you should check whether the instances are truly destroyed.
My Grasshopper version is 0.9.0014. Rhinoceros version is 4.0 SR9. I use Windows 7.
Just because you show a window from a class that is later garbage collected doesn't mean the window will also be closed and collected automatically. Clearly they are on the screen and being used and therefore the GC will leave them alone. Furthermore, if these windows have references to the components that spawned them, they will also prevent those components from being garbage collected.
It is certainly possible that documents are not properly collected, but it sounds like what you're seeing is correct behaviour, not the manifestation of a bug. If you show these windows you're also in charge of hiding/disposing them. This can be done either via GH_DocumentServer events or via the methods on GH_Components that are called when the owner document context changes but it will not happen automatically.
From what I understand the Garbage Collector kicks in when it feels the memory is running out and it needs to clean up a bit. I have no idea whether half an hour is guaranteed to contain at least one GC sweep.
--
David Rutten
david@mcneel.com
Poprad, Slovakia
Thank you very much for the detailed reply and I'm sorry for making you busy.
My understanding is totally incorrect. I will try again based on your suggestions.
Thanks.
I did some testing with document finalization and it seems the documents are properly garbage collected. However it's always possible I did not test a certain case which would result in faulty behaviour.
--
David Rutten
david@mcneel.com
Poprad, Slovakia
Welcome to
Grasshopper
Added by Parametric House 0 Comments 0 Likes
Added by Parametric House 0 Comments 0 Likes
Added by Parametric House 0 Comments 0 Likes
Added by Parametric House 0 Comments 0 Likes
Added by Parametric House 0 Comments 0 Likes
© 2024 Created by Scott Davidson. Powered by