Can anyone tell me how to create a program as memory efficient as possible.
Do you need to create all objects in code to do this?
Are there any more ways than, Free, FreeAndNil etc to release memory once
my program has finished with it.

I have a program that has a timer and every 10 seconds it runs code to process instructions on a database. I use query's to access the data and also to update my data. But as my program runs, which is 24/7, I can see the Mem Usage in Task Manager slowly accumulating over time. I create all my query's in code and free them up once im finished so I am struggling to think why this memory is accumulating over time.

I am using Delphi 5 Pro and my app is a standard windows exe.

Any help would be greatly appreciated
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.


you could:
use less Database object as posssibly
create object dynacmic instead of placing on form
free up ( after use.

hope helps
Is it possible for this routine to take longer than 10 seconds to complete? If so, depending on how your code was written, you may be creating objects that are already created and then loosing the reference to them.

Just a thought.

You may also have a memory leak somewhere in your code that you may not see right now.
if you create objects with AOwner set to self you will not have a memory leak if you close
the application but during the runtime of the programm you will
experience incrementing memory usage

Fundamentals of JavaScript

Learn the fundamentals of the popular programming language JavaScript so that you can explore the realm of web development.

HotRod40Author Commented:

Is there any other options to set AOwner to other than Self ?

I've seen code where a form is created with Application as the owner. I personally do not like this coding style. I also don't like to code objects that stick around for longer than they need to be.

However, I have seen some recent posts on EE where they talk about memory leaks in the Query objects (I'm not a DB guy so I'm not really sure if this applies to you). Your code may be correct and the problem may lie elsewhere.

Here are some links

you can set the owner to nil

that also means you have to free the objects yourself.

but that also means that you can free the objects at the time you
want and you must not wait until the Owner is freed.

for instance:

procedure formcreate()
  myPanel := TPanel.create(nil)
  mypanel.parent := Mainform;  { to show it somewhere }

procedure Formdestroy();

you can call the anywhere you like
but it also means if you forget it you have a memory leak after the programm is closed

gandalf_the_white is correct, however to avoid any confusion, you can still create the panel with an owner and free it anytime you like before the owner is freed. When this happens, the owner will Remove that component from its internal list so that it knows not to free it when it is destroyed.

However, I still bet the leak isn't in your code but in the components you are using (then again, I haven't seen your code).

my point was that if you create components with Owner set to the form during runtime
they are not freed until the program is closed.

that means your memory usage will raise during the execution if you create ANY Components during runtime.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.