Solved

Inconsistant memory usage at startup

Posted on 2006-06-27
6
333 Views
Last Modified: 2010-04-05
I have an WIN32 application made with Delphi 6. It's used about 27 Mb of memory at startup but sometime, the memory usage peak at 60, 100 and even 160 MB in Task Manager. After Initializing, the App create a DataModule, who itself instantiate some customs Classes, and create the MainForm (in full screen). Nothing special worth for posting here anyway i think. It have no specific patern for the memory peak since it happen sometime two time in a row or after four normal memory usage startup. There is no slowdown either (AFAIK) using the app even if it's mem is at 160MB.

Why would a thing like this crappy memory peak happened?

And how did i find wich component used this much memory?
I tried InstanceSize but it look like it didn't return the global size of my object and it would be too long to calculate it for every object i created.

I have tried to delete most object creation and use breakpoint to see where in the code the memory seem to rise but since it happen at random, i really got hard time to reproduced it!

Any suggestion? Third party software who may help? Maybe i look at the problem the wrong way...

Thanks for any clue!
0
Comment
Question by:TELEBECINFO
  • 3
  • 2
6 Comments
 
LVL 4

Accepted Solution

by:
kenpem earned 250 total points
ID: 16997430
It certainly won't be at random. There will be a pattern, even if it is difficult to spot. The DataModule obviously has to interact with a database somewhere, and that can eat memory.

Is this a serious problem? My experience has been that the app will consume the resources it needs as it needs them, and eventually level out. Does it come down from that 160MB peak? Or just keep going up forever? A constant rise would indicate a memory "leak" somewhere - an object/component/resource that's being created (again and again, usually) but never destroyed.
0
 
LVL 9

Assisted Solution

by:sun4sunday
sun4sunday earned 250 total points
ID: 16998255
If the usage of more memory only at start up it may not  be a memory leak.
Application is taking the resources to initialize.

To avoid this generally(in case of a no-memory leack)
Don't open all the tables at start up
Create Forms dynamically instead of opening it at startup of the applicaiton
Have a look on this PAQ
http://www.experts-exchange.com/Programming/Programming_Languages/Delphi/Q_21891505.html

Also can try
MemCheck   http://v.mahon.free.fr/pro/freeware/memcheck/

sun4sunday
0
 

Author Comment

by:TELEBECINFO
ID: 17001613
No database is opened at start up and no database at all in the projet (no databinding field of any kind).

@sun4sunday
"If the usage of more memory only at start up it may not  be a memory leak.
Application is taking the resources to initialize."
So, we can say the ressource taking while initializing vary in my case. Now i need to find the "why"...

@Kenpem
When it's peak at 160MB after startup, there is no other memory rise other than normal forms creation as the user use the app.
I take a look at your link but the application quite fast at start up (about 5 second, a bit more if the screen is resize). And it 6.36 MB large (mostly because large image integrated in ressources).

I'll detail a bit more what happening at start up from my dpr :

1- Create DataModule
 [In the datamodule...]
 1.1- Create a thread (TThread) that connect a web site looking for update (Thread is killed after15 sec if no response)
 1.2- Create a custom TComponent class who read a XML file and store the values in different property.
 1.3- Create a custom TComponent class for communication purpose with a DBL system (yeah, old application...)
   1.3.1- Create custom storage classes with array
   1.3.2- Create TStrings object
   1.3.3- Create others custom TComponent class

2- Using EnumDisplaySettings and ChangeDisplaySettings, validate actual screen size and color, changing it as necessary for best supported resolution for 1280x1024, >16 color.

3- Mainform creation
4- Loginform creation
5- Others static form creation (i delete them while i tested but the memory problem still happen)
5- Application.Run

On Mainform FormShow event, it load it background with a  LoadFromResourceName (~3 MB image).
On Mainform FormActivate event, it LoginForm.ShowModal.

On LoginForm.FormShow, it get the users list from a flatfile and display it in a pick list.

Thats it.

I can create LoginForm instead of ShowModal on the MainForm.OnActivate but i don't think the problem is there since i'll just reported the creation a few step later.

I had find memcheck from previous search before posting here but my guess is that it more for finding memory leak. In my case, there is not object destruction yet after start up so it's a leaking issue (unless i mistunderstood what a leak is). Sometime it had the good size, sometime not....
 

0
ScreenConnect 6.0 Free Trial

At ScreenConnect, partner feedback doesn't fall on deaf ears. We collected partner suggestions off of their virtual wish list and transformed them into one game-changing release: ScreenConnect 6.0. Explore all of the extras and enhancements for yourself!

 

Author Comment

by:TELEBECINFO
ID: 17002212
I forgot a some word in my last sentence :

"I had find memcheck from previous search before posting here but my guess is that it more for finding memory leak. In my case, there is not object destruction after start up so *i think* it's *not* a leaking issue (unless i mistunderstood what a leak is)."
0
 

Author Comment

by:TELEBECINFO
ID: 17234162
Finally, the problem was with a third party component i was using with the thread to know if there was an update available. The component was updated without my acknowledge.

For reference purpose, the component (THttpCli (c) 1997-2005 F. Piette V1.88) is used to connect to a web server, get a MD5 for specific files (calling a php page) and compare it with user's file. The problem occur when calling the hashing php page, on the OnDocData function. The previous code was
FData := FData + String(Buffer)
and with the new version, it now
FData := FData + PChar(Buffer)

I have no idea why it make the memory peak but anyway, my problem is now resolve.

Thanks


0
 
LVL 4

Expert Comment

by:kenpem
ID: 17237314
Glad you got it sorted out!
0

Featured Post

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

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

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…
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 Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …

770 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