out of resources

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
LVL 1
pedeAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

MadshiCommented:
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
PalamedesCommented:
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
MadshiCommented:
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
Cloud Class® Course: MCSA MCSE Windows Server 2012

This course teaches how to install and configure Windows Server 2012 R2.  It is the first step on your path to becoming a Microsoft Certified Solutions Expert (MCSE).

PalamedesCommented:
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
MadshiCommented:
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
PalamedesCommented:
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
MadshiCommented:
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
MadshiCommented:
P.S: Under winNT (or Linux or BeOS) we don't have such handle restriction. That's a win9x problem...
0
PalamedesCommented:
Hmmm the more I think about it the more I realize what a large restriction it is..

-Pal
0
fkmfkmCommented:
Is Handles the only thing that consumes system resources ?

It there are way to detect how many handles a form consumes ?
0
MadshiCommented:
>> 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
TheNeilCommented:
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
MadshiCommented:
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
pedeAuthor Commented:
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
MadshiCommented:
Thanx...
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
TheNeilCommented:
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
MadshiCommented:
Hehe, you didn't need to apologize, you couldn't know that!   :-)
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Delphi

From novice to tech pro — start learning today.