[Webinar] Streamline your web hosting managementRegister Today

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 146
  • Last Modified:

Resources burn up!

I'm working with:

CreateCompatibleDC, CreateCompatibleBitmap, DeleteObject and DeleteDC.

I have a re-enterable routine that will size the Compatible Bitmap as needed.

The problem is:

if Bitmaphandle<>0 then DeleteObject Bitmaphandle ' Previous bitmap
CreateCompatibleBitmap .... 'build bitmap and store in Bitmaphandle

Doing this, repeatively (when size changes happen), causes exhaustive resource burning (in the high percentage ranges, like almost 10% each time).

There is only one hDC being used, it's not deleted, each DeleteObject returns 1 (success), so I'm at a large loss as to why this is happening right now, because if I delete the object, the memory should be freed up, but it isn't (until the program exits, which is bad).  Is there a way I can get the system to do this FREE up when I need it to?

I must be over looking an API function for GC.  It just makes no sense that I need to ask for it.  Getting past this, will allow me to finish a calendar stamping function class (that lets you stamp a calendar onto a bitmap).

Any stabbers?
0
FunkyMeister
Asked:
FunkyMeister
  • 3
  • 3
1 Solution
 
GivenRandyCommented:
Make sure you delete both the Pen and Brush after using them.  If you defined Pen and Brush, use:

Result = DeleteObject(Pen)
Result = DeleteObject(Brush)
0
 
FunkyMeisterAuthor Commented:
I pull up all the brushes (no pens) I need at the start.  Fonts are a problem, I keep rehashing the same font (just for size), there must be a better way to do that.  I also remove and rebuild the bitmap (because it's size is not right for the current needs).

I create the compatible hdc, brushes (2) and borrow the desktop hdc.

At the end of the program, I release the desktop dc I borrowed, the two brushes are deleted as is the compatible hdc.  (The bitmap is done as well, if it still exists.)

At a complete loss.  Only thing I can think of is the font is causing it.  I've checked everything else.  (I think I'm going to make it only make 1 font change and see if the leak vanishes.)  It causes System and GDI to drop like a rock.  I've seen it go from 80%+ to less than 30% in a split second.

Thankfully I watch them and cancel the operation of the program (so it doesn't cause a crash).
0
 
GivenRandyCommented:
Compuware has DevPartner Studio which does a great job of detecting things like this:

http://www.compuware.com/products/devpartner/studio/

They used to have a trial period, which you might check.
0
The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

 
FunkyMeisterAuthor Commented:
Actually, it looks like the problem is the bitmap not being deteted by the DeleteObject.  It's returning a 1 as being true, but it's incorrect, as every time the bitmap is deleted and recreated, the previous map appears to remain in memory.  I tested the font change, it's not the issue, as soon as the map gets larger, boom.  Resources drop like a rock (but they shouldn't).

I'll check that dev partner and see what it has to offer, but do you or anyone have a "sane" DeleteObject example that actually DOES delete a Compatible Bitmap?
0
 
GivenRandyCommented:
0
 
FunkyMeisterAuthor Commented:
I gave it to you because I already found the answer (prior), but you found better resources for me to peek at, so I thought it'd make you happy.  :)

I solved all the problems earlier by realizing something in the docs for deleteobject.  If it's IN the Device Context, it can't be removed (makes sense), but what they don't tell you is it returns an ok response if it didn't delete it.  :/  SDK fooleries.  :(
0

Featured Post

The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

  • 3
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now