Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 381
  • Last Modified:

Why is this eating my resources?

Hi Folks!

This is the case:

I have a listbox, a trackbar and after the trackbar has been changed I collect its value by means of adding it to the listbox. The trackbar runs from 0 to 9 in 9 steps and a buttonclick 'delivers' the trackbars value to my listbox.
This is what I made of it in code:

 Listbox1.Items.Add(InttoStr(Trackbar1.Value));

Some 'monster'is eating resources and I just hear that this could very well be that monster...I however fail to comprehend why this code would do that and if another approach would be more gentile to my resources I'd be more than happy to hear that from you...

Regards Peter

Please comment it as severely as my resources get eaten, this will help me comprehend :)
0
PeterdeB
Asked:
PeterdeB
  • 5
  • 5
  • 2
2 Solutions
 
Russell LibbySoftware Engineer, Advisory Commented:

Peter,
Just a thought... do you ever clear the list box values, or do you keep appending?

Regards,
Russell




0
 
BlackTigerXCommented:
Listbox1.Items.BeginUpdate;
try
  ...add all the values you are going to add (like in a loop or something)
   Listbox1.Items.Add(InttoStr(Trackbar1.Value));
finally
  Listbox1.Items.EndUpdate
end;
0
 
PeterdeBAuthor Commented:
Hi Russell!

Well the total amount of values I collect is 18 max. After they're collected I use them to replace some words in some textfile and the app shuts down. So the answer should be no but since I start with an empty listbox each time I didnt think this would be a problem.

Regards Peter
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
Russell LibbySoftware Engineer, Advisory Commented:

If the listbox ItemCount never exceeds 18, then no, this is not your problem. It would only be a problem if you continously added items (in the thousands) and never cleared the items list.

Russell
0
 
Russell LibbySoftware Engineer, Advisory Commented:

When tracking down memory usage, try to first determine how much, and at what rate the memory is being consumed. This will give you some idea of what you are actually looking for. Larger memory consumption is usually easier to find, as the problem is usually a glaring one. Small memory leaks on the other hand can be tough to track down.

Then evaluate your code looking at:

1.) Loops that are executed multiple times. (Its not the loops so much as it is the code in the loop.)
2.) Object creations without a corresponding Free/Destroy for the object
3.) Memory allocations without (getmem, allocmem, etc) without a corresponding FreeMem.
4.) Lists that are constantly appended to but never cleared.

If a code walkthrough fails, then you should probably turn to a memory checking program to see where the leaks may be coming from.

Russell
0
 
BlackTigerXCommented:
forgot to ask... what version of Windows are you using? and what resources are being eatten? memory or CPU?
0
 
PeterdeBAuthor Commented:
Hi Folks!

Tnx for responding Russell and BlackTigerX.

BlackTigerX,

I run XP SP2 and it seems its my CPU that complains and it does so after a period of time regardless of whether I'm actually doing something with the program, but before I turn this into a complete drama I will install some program to get a better idea of what my program actually wants for lunch. I will also exclude any other participants which may be contributing without me being aware.

Russell,

Are you familiar with any of those programs, can you recommend some program? I installed one a year ago or so and it came up with 8 blocks that were not freed every time the program was run and shut down. I never figured out how to solve that issue so shortly after I uninstalled it since I could very well do without the JustBeforeShutDownNotifyingMessage of 8 blocks and killing the message seemed equivalent to remove the whole app from my delphi tools box. I forgot the name however.


Regarding the code fragment >

is a stringlist the better choice for temporarily storing these few values? The reason I chose the listbox is mainly because of the fact I could clearly see and check whether all values were correctly stored prior to having them exchange values in the textfile. I'm know reading Delphi's Help on the stringlist thing cause I never really used it that much.

Regards,

Peter
0
 
Russell LibbySoftware Engineer, Advisory Commented:

1.) For my own stuff, I just tend to use a memory manager replacement. That way I can track allocations and deallocation. Regarding others, I could not say; though Im sure a quick goole would yield a few. (free is good ;-)

2.) Behind the scenes, a listbox uses a TStrings object for string storing, so unless you need the visual component, a TStringList would be a natural choice. (and very easy to drop in / replace the existing code).

3.) If its the CPU that is running high, and you can attribute it to your process (by using task manager), then check your code for loops / timer events that run OFTEN. Be aware that calling Application.ProcessMessages (from your previous q) will use CPU time.

Russell
0
 
PeterdeBAuthor Commented:
Hi Russell!

Just finished installing some programs and the first that came up with some testing results was Sleuth Codewatch 3. It did not detect any resource nor memory leaks. The list of loaded modules however didn't look okay to me. Several modules had 0h as their data size in combination with n\a as version number and last but not least no path reference. I reckon those could be function called from a DLL or something but I need to dig in deeper to comprehend all of the report. I also don't know whether the testing params were adequatelly set so until I further dig in I better not assume too much.

Okay then Ill go for the stringlist and well mind me in the last lines of your comment I see a reference to my friend TTimer which I indeed use in my program and also the comment on the app.processmessages shall be taken into consideration :)

Regards Peter

I will return :)
0
 
PeterdeBAuthor Commented:
Aha > Sleuth only recognizes windows pe files so that explains some of my findings I stated above. Some dlls it doesnt recognize either and the rest seem to be drivers or something ?? > .ax

Peter
0
 
Russell LibbySoftware Engineer, Advisory Commented:
quick goole -> quick google (bad typing)

1.) Some modules won't display this, depending on how they are mapped in (and if they are system libraries)
2.) CPU usage or hogging is different then mem resource usage, and it wasn't clear at first which you were referring to. If its just CPU usage, then run your program in the ide, monitor the task manager, when it starts spiking (based on your program), pause your program and evaluate the call stack to see what is going on.

cya soon

Regards,
Russell
0
 
PeterdeBAuthor Commented:
Ok Russell, I get your message :)

Regards Peter
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

  • 5
  • 5
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now