Page Index Toggle Pages: 1 Send TopicPrint
Normal Topic When the Dispose method is called? (Read 1225 times)
jpinera
YaBB Newbies
*
Offline


I love YaBB 1G - SP1!

Posts: 10
Joined: Jul 4th, 2011
When the Dispose method is called?
Jul 6th, 2011 at 6:21am
Print Post  
I have a class derived from ShapeNode that use some disposable elements such as fonts or pens. I call the dispose method when the node is removed from the diagram, but in this case, the redo function does not work if it needs to recreate the node. If Dispose method is needed, redo works fine, but I don't know when the object is disposed.
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: When the Dispose method is called?
Reply #1 - Jul 6th, 2011 at 7:54am
Print Post  
I don't think the control explicitly calls Dispose. You could dispose the GDI obejcts from a Finalize override, which will be called by the GC when there are no more references to the item. Alternatively, create the objects in an OnAdd override and release them in OnRemove, those methods should be called by undo/redo.

However you should keep GDI objects short-lived, and better create them only in the Draw override; otherwise you might run out of GDI resources when the user draws a lot of items. Instead, use the Brush and Pen classes from the MindFusion.Drawing namespace as members of your class, and only create their corresponding GDI object when drawing.
  
Back to top
 
IP Logged
 
Page Index Toggle Pages: 1
Send TopicPrint