Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win


Inconsistant memory usage at startup

Posted on 2006-06-27
Medium Priority
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!
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2

Accepted Solution

kenpem earned 750 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.

Assisted Solution

sun4sunday earned 750 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

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


Author Comment

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

"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"...

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....

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!


Author Comment

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)."

Author Comment

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.



Expert Comment

ID: 17237314
Glad you got it sorted out!

Featured Post

Tech or Treat! - Giveaway

Submit an article about your scariest tech experience—and the solution—and you’ll be automatically entered to win one of 4 fantastic tech gadgets.

Question has a verified solution.

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

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
Suggested Courses

609 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