Solved

EOutOfResources problem

Posted on 1998-01-15
11
258 Views
Last Modified: 2010-04-04
I write a very large application (a lot of forms, all created at the beginning). When the application reached a certain size, I got an EOutOfResources exception.

One of the dominant side effects is that when the application is running, from some point it refuses to open windows, does not show pop-up menus or parts of them.

at the help they say it is because too much handles are in use, but I tried solutions that would work if this is the reason, and they didn't work. Furthermore , I wrote an application that opens hundreds of forms,buttons .. without
any error .
I work on a computer with 200MB Ram , so memory is not the
problem.

anyway , i would like to know , what are the various reasons
to get the EOutOfResources exception , and how can i trap resource leak (NT 4.0 environment  ) ?

Thanks , Ori.
0
Comment
Question by:oris
11 Comments
 
LVL 5

Expert Comment

by:ronit051397
ID: 1356687
Are all your forms loaded when the project is loaded?
If yes, Then load only the neccessary forms for the current operation.
When you close a form do you call Release?
If not, then on the form close event you should call Release;
Did you verify that none neccessary objects are freed?
Use Numega to locate memory leaks.

Ronit,
Kfar Saba

0
 
LVL 8

Expert Comment

by:ZifNab
ID: 1356688
about memory leaks :

There are some commercial programs on the net for finding such leaks.
But, I found one, which is freeware and is good, you can find it at  : http://home.sprynet.com/sprynet/rrm/. It calls snoop.

If you can't find it, i can send it to you

Good luck!
Regards,
ZifNab.
0
 
LVL 3

Expert Comment

by:Matvey
ID: 1356689
Ronit...I thougth you are from Israel!

Me too, I'm from Petach-Tiqa...

Matvey
0
 
LVL 5

Expert Comment

by:JimBob091197
ID: 1356690
What ver of Delphi?
0
 
LVL 5

Expert Comment

by:inter
ID: 1356691
Causes
------
EOutofResources error is reported by the Windows whenever a handle is to be created or new class is to be registered to the system. Any handle creation function (DC, menu,window-form) returns 0 and Delphi interpret this as a OutofResources error.
By my opinion this is not correct, or one step more is needed to understand the actual error.The delphi should call GetLastError, but it does not.
When I search this error in VCL source code I found that it is in the following units:  Graphics, Forms, Menus.

Limits
------
Windows 95 is limitted to 16384 handles per object class, i.e. this much of menu or window locks up the system. However Windows NT does not have a restriction on number of handles.


Suggestions
-----------
Asside from the other friends suggestions I have the following:
1 - If you are creating several TCanvas, TPen, TBrush, TMetafile etc.(in general memory consuming GDI objects), be sure to call Free for them.
2 - As a rule of thumb do not precreate more than 20 such resources on FormCreate.
3 - Remember that out of resources error is cummulative. i.e. it may not appear at the begining; by forgetting to release handles the system resources may be used up gradualy.
4 - If you sure that you free the handles allocated by your program (manualy by calling constructors of TCanvas, TPen etc), try to maintain the list of handles manualy created by
program and FREE them ALL in ExitProc or finalization section. Because when your program terminated erronously some of the Free methods may not be called
5 - If you are making use of large bitmaps just for painting the background of forms etc. Create bitmap, paint it and release it if you are not doing time critical painting (animation).

GOOD LUCK!
0
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 

Author Comment

by:oris
ID: 1356692
I'd like to add some details:
- I'm working on Delphi 2.0
- I tried BoundsChecker and it gave me only information about minor memory/resource leaks
- The NT task manager says that I'm using no more than 1400 handles at a time.
- The failure happens even if I shutdown the computer and then execute the application (there are no remains of executions from the past), before I have the chance to use any exit routines.
- My application is a large MDI application. Dozens of forms are created in the dpr file as MDI childs.
- There are almost no dynamic creations in the FormCreates. I do use Free.
- I would like to emphasize that I suspect Pop-up menus and commands like ShowMessage or MessageDlg, which create new windows.

thanks.
0
 
LVL 5

Expert Comment

by:inter
ID: 1356693
oris,
-I am still working on it but could not find menu or window related cause for your problem.
-However, (probably you know these but) there are two things to remind. First of all there is a patch of System.pas which fixes a 32 bytp memory leak in allocation. It is directly available from
http://www.borland.com/devsupport/delphi/downloads/index.html
-And while I try to determine the cause of the problem, I have found that suspended TThread (classes.pas) instance keeps the program from terminating. But, I still use Delphi 2.00, this problem may be fixed in 2.01.
-Also, there is a component called SNOOP for detecting memory leaks etc from http://sunsite.icm.edu.pl/delphi/ zipped into snoop110.zip

Please, write comments, I really interested the problem, the EXPERT points are not important.

Regards,
Igor

0
 

Author Comment

by:oris
ID: 1356694
I solved the problem by using less handles.
Igor, I'd like to give you the points, but I can't do that until you submit another answer.

thanks.
0
 
LVL 5

Expert Comment

by:inter
ID: 1356695
Thank you very much oris,
However, to gain that much points I'd like to do more for you. Tell me if I can help in Delphi or windows stuff (component-utility etc.)
Thanks again,
Igor
0
 

Author Comment

by:oris
ID: 1356696
Igor,
I really don't need anything, and I do not expect anything. If you think you got really cool stuff, with no regard to my question, you are welcomed to send it to me. My email is
oris@math.tau.ac.il.

thanks. (please submit an answer).
0
 
LVL 5

Accepted Solution

by:
inter earned 400 total points
ID: 1356697
Thanks friend,

Have a nice programming.

Igor (inter@kosgeb.tekmer.gov.tr)
0

Featured Post

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…

744 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now