[svn.haxx.se] · SVN Dev · SVN Users · SVN Org · TSVN Dev · TSVN Users · Subclipse Dev · Subclipse Users · this month's index

Re: MFC question: is it really necessary to call DeleteObject?

From: Andreas Nicolai <Andreas.Nicolai_at_gmx.net>
Date: 2007-10-10 17:04:23 CEST

Hi again,

On Wed, 10 Oct 2007 01:42:34 -0400, Stefan Küng <tortoisesvn@gmail.com>
wrote:

> Yes, and that's one of the reasons MyGraph.cpp is slow and can run out
> of GDI objects.
> You have to delete those objects manually.
> (btw: if you like to replace MyGraph.cpp, that would be great!)

Well, just hacked toghether a chart control a few months ago :-), but
using the Qt toolkit (see http://qnanwidgets.sourceforge.net). But even if
I were to reimplement that using MFC, this would take some time and effort
(too much for me right now), so I guess this can be a low priority upgrade.

I like the idea of Hans-Werner and will create a wrapper class template
for all the MFC objects that need to call DeleteObject used in
MyGraph.cpp. How about something like:

AutoDeleteObject fontObj = AutoDeleteObject<CFont>();
CFont * f = fontObj.object();

// when fontObj gets out of scope, the DeleteObject() function for the
CFont object is called automatically.

So the class could be something like...

template <typename T>
class AutoDeleteObject {
     T m_theObject;
     // prevent copying
     AutoDeleteObject(const AutoDeleteObject& );
     // prevent assignment
     AutoDeleteObject & operator=(const AutoDeleteObject&);

public:
     AutoDeleteObject() {}
     ~AutoDeleteObject() {
         m_theObject.DeleteObject();
     }

     T * object() { return &m_theObject; }
}

Now I'm wondering why Microsoft doesn't have a simple class like that in
their libs? Or do they?

Anyway, thanks for the suggestion!
Andreas

-- 
Andreas Nicolai                         anicolai@syr.edu
PhD Candidate, M.A.M.E                  (315) 443-2218
Syracuse University
151 Link Hall
Syracuse, NY, 13244
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tortoisesvn.tigris.org
For additional commands, e-mail: dev-help@tortoisesvn.tigris.org
Received on Wed Oct 10 17:28:40 2007

This is an archived mail posted to the TortoiseSVN Dev mailing list.

This site is subject to the Apache Privacy Policy and the Apache Public Forum Archive Policy.