Solved

EOutOfResources problem

Posted on 1998-01-15
11
264 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

932 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

11 Experts available now in Live!

Get 1:1 Help Now