?
Solved

out of resources

Posted on 1999-12-21
17
Medium Priority
?
152 Views
Last Modified: 2010-04-06
Hi

I have a pretty big application which uses quite a lot of bitmaps. The problem is that after running for a while, win95 runs out of resources, and I get a message that I cant draw on canvas. This does not happen on NT.

Isnt it pretty likely that its caused by the amount of bitmaps? I dont know for sure how many there is, maybe 50 or so... I find it strange, though, that it only happens after a while. Its not possible just to sit down and recreate the crash.

Good advice wanted. It might not be possible to cut any bitmaps out. Not even to collect them in a bitmap list (cant remember the component name right now).

Regards,
Pede
0
Comment
Question by:pede
  • 9
  • 4
  • 2
  • +2
17 Comments
 
LVL 20

Expert Comment

by:Madshi
ID: 2297583
You can download the little tool "ShowRes" from my homepage:

http://beam.to/madshi

This program shows you exactly the resources, win95 has problems with. And yes: A lot of bitmaps brings win95 to its knees. Why can't you use a TImageList instead? That's the common solution! How many forms does your project have? Do you let Delphi create them (look in your project for Application.CreateForm) or do you create them yourself?

Regards, Madshi.
0
 
LVL 4

Expert Comment

by:Palamedes
ID: 2298445
What about using a different file type, like JPG or GIF.  They are a heck of a lot smaller and might be a solution.  (and if it isn't just ignore me.. hehe)

-Pal
0
 
LVL 20

Expert Comment

by:Madshi
ID: 2298524
Hi Pal,  :-)  this kind of resources is only about restricted handles, not about memory. Look at the documentation of the "CreateWindow" API:

Windows 95: The system can support a maximum of 16,364 window handles

Okay, here we're talking about GDI resources, but it's the same. Each bitmap takes one (or more) GDI handle(s), it doesn't matter how large the bitmap is or whether it is JPEG or GIF or uncompressed...

Regards, Madshi.
0
Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
LVL 4

Expert Comment

by:Palamedes
ID: 2298542
ooooh,  I see.  Hmmm.  Well then, how about using an ImageList, or even simpler, placing all the images on the HD and load/free them as needed?

(btw, 16,364 is a lot of handles... Though I am sure others have run into this same problem before.. What other common solutions are there?)

-Pal
0
 
LVL 20

Expert Comment

by:Madshi
ID: 2298563
Yes, the common solution is an ImageList, because an ImageList consumes only 1 handle (or 2, if it has a mask), independent on how many bitmaps it holds.
16K sounds like a lot, but that's not per application, but per system. And when Windows is started, you only have about 12K or so left.
My biggest Delphi project consumed >60% of the system resources in the beginning. So I replaced all the bitmaps by an ImageList and created the forms only when needed. Now it "only" consumes about 10%. That's still quite much, but I can live with it.
0
 
LVL 4

Expert Comment

by:Palamedes
ID: 2298568
This handle thing is new to me let me see if I understand a little better..

Does each Component on an application consume a handle of its own?  So if you have 50 radio buttons each one has a handle.. (thus the invention of the RadioGroup box... which I assume only uses one.)

etc?



0
 
LVL 20

Expert Comment

by:Madshi
ID: 2298758
Each component that derives from TWinControl consumes (at least!) one handle. Components that derive from TGraphicControl (I think that was the name) do normally NOT consume a handle (except when they have a bitmap property, but then the bitmap consumes one handle, not the component itself). Some components consume more than one handle. I guess, a RadioGroupBox consumes one handle per radio button...
0
 
LVL 20

Expert Comment

by:Madshi
ID: 2298761
P.S: Under winNT (or Linux or BeOS) we don't have such handle restriction. That's a win9x problem...
0
 
LVL 4

Expert Comment

by:Palamedes
ID: 2298963
Hmmm the more I think about it the more I realize what a large restriction it is..

-Pal
0
 

Expert Comment

by:fkmfkm
ID: 2299527
Is Handles the only thing that consumes system resources ?

It there are way to detect how many handles a form consumes ?
0
 
LVL 20

Expert Comment

by:Madshi
ID: 2299819
>> Is Handles the only thing that consumes system resources ?

There are different kind of resources. The kind we're talking about here is the win9x handle restriction. And this kind of resource is only consumes by handles.
But there are other resources like memory or harddisk space or CPU usage or ...

>> It there are way to detect how many handles a form consumes ?

Well, there is a way to detect that exactly, but it needs some deep hacks. If you don't need to know it *exactly*, you should look at the system resources (either in Control Panel -> System, or by using my tool, link above) before and after you create that form. Simply put a message box in your project's sources before the "Application.CreateForm(TYourMainForm, YourMainForm)" line and after that. Then you can calculate how many resources your form (in %) consumes.
0
 
LVL 5

Expert Comment

by:TheNeil
ID: 2303556
There's no definitive answer to this question as you haven't said what you're currently doing so here are a list of things to keep in mind:

1. Make sure you FREE your bitmaps when you're finished with them

2. Don't reload bitmaps into TBitmaps over existing ones - free the TBitmap then create it again

3. Avoid Run Length Encoded bitmaps (RLE) as the decompression method wastes resources like nobodies business
0
 
LVL 20

Expert Comment

by:Madshi
ID: 2303597
Hi TheNeil,

welcome to the EE-family...  :-)

Well, may I say one friendly request? Could you post a *comment* next time rather than an *answer*? Because before you there were already a lot of comments added in this question and we should let pede decide which answer (respectively comment) earned the points... So it's usual practise here in the Delphi forum to write only comment in such a situation. Of course you couldn't know that - especially because the other forums behave different.

Thank you...   (-:

Regards, Madshi.
0
 
LVL 1

Author Comment

by:pede
ID: 2307410
Hi

Thanks for all the comments, eventhough they werent all for me ;)

TheNeil is right, there is no definitive answer to this. But so far I've used Madshi's program, and it have been very useful. At least it makes it possible to see if the changes to the program have an effect or not. Please propose an answer Madshi, and you will get the points.

Regards,
Pede

0
 
LVL 20

Accepted Solution

by:
Madshi earned 80 total points
ID: 2307420
Thanx...
0
 
LVL 5

Expert Comment

by:TheNeil
ID: 2322125
Oops, didn't realise how it all worked around here. Apologies to one and all etc etc etc

The Neil

PS Windows will have no problem creating the handles for 50 bitmaps so I think you're going in the wrong direction when you start messing around with handles and imagelists. It all helps of course but...
0
 
LVL 20

Expert Comment

by:Madshi
ID: 2322190
Hehe, you didn't need to apologize, you couldn't know that!   :-)
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
How can you see what you are working on when you want to see it while you to save a copy? Add a "Save As" icon to the Quick Access Toolbar, or QAT. That way, when you save a copy of a query, form, report, or other object you are modifying, you…
Stellar Phoenix SQL Database Repair software easily fixes the suspect mode issue of SQL Server database. It is a simple process to bring the database from suspect mode to normal mode. Check out the video and fix the SQL database suspect mode problem.
Suggested Courses

600 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