?
Solved

Resources burn up!

Posted on 2003-03-24
6
Medium Priority
?
144 Views
Last Modified: 2010-05-01
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
Comment
Question by:FunkyMeister
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
6 Comments
 
LVL 9

Expert Comment

by:GivenRandy
ID: 8199643
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
 
LVL 1

Author Comment

by:FunkyMeister
ID: 8200793
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
 
LVL 9

Expert Comment

by:GivenRandy
ID: 8202860
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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 1

Author Comment

by:FunkyMeister
ID: 8203695
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
 
LVL 9

Accepted Solution

by:
GivenRandy earned 375 total points
ID: 8204732
0
 
LVL 1

Author Comment

by:FunkyMeister
ID: 8216035
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

[Webinar] Lessons on Recovering from Petya

Skyport is working hard to help customers recover from recent attacks, like the Petya worm. This work has brought to light some important lessons. New malware attacks like this can take down your entire environment. Learn from others mistakes on how to prevent Petya like worms.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Suggested Courses

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question