I added the dispose for these regions in my code, but am unsure where to place the strFormat dispose. Between version 1.0.5 and 1.0.6 I changed where the strFormat is set, and also changed it's scope. (added current version as attachment)
Do I still need to dispose this object (if yes where?),
What you have to find out is
- where and when is a object created?
- where does you code release last reference to the object?
Knowing this information you can find any code path where an object may slip without you disposing it.
Using the VS search tool is helpful here, highligh the class field and select "Find All References", you can now see a list of all code lines where this field variable is used, they are either read operations or assignment operations. All assignments are a places where you must dispose the previous instance (if no other part of code is also holding a reference to same object, this would complicate things
![Smile :) :)](data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7)
). In addition you need to dispose when explicitly called for.
Try this with the m_strFormat field, you get a long list of read operations and only one assignment, which is the declaration where also a new instance is assigned. So here you only need to dispose it when consumer calls Dispose method.
Try the same with the m_graphics field, only 3 references is now found; the declaration (no assignment), 1 read operation, 1 assignment operation (the property setter). In property setter you must dispose the previous instance (as per my previous post). In addition you need to dispose it when consumer calls Dispose method.
About the Dispose method, your base class here (Control) implements IDisposable, so you have a overrides for Dispose(disposing), this is ok, you are also here Disposing the Graphics which is correct and calling the base. As implied above you need to add Dispose for m_strFormat also in this method. There is also the possibility of handling the Dispose event instead of overriding.
Your Dispose()
overload is not needed, you should remove it because it does not fit in the IDisposable pattern. Overloads is only called if the object cast as this specific type, otherwise the base method is called. While your code in this method in this case probably is correct and most likely doesn't differ from the base functionality, there is only room for errors doing this. The base Dispose() will call your Dispose(disposing) override.