problems with freemem when closing a file

Posted on 2005-05-12
Last Modified: 2010-04-05
My Delphi 7 program seems to behave well when it is running on Windows XP.  Yet the same program running onWindows  Server 2003 gives an error when I clos ethe program down, citing problems with Freeing up memory. is there much difference bewteen the two platforms when it comes to running Delphi (version 7). If Xp cannot find a problem, how can I find out what is wrong.

I create a number of dynamic arrays while the program is running. My  Closing instruction (when the user stops the program) is to use the finalze procedure to kill off the dynamic arrays.  Do I have to close them in any particular order?  When using XP it seems to make no difference if I finalise the dyanamic arrays or not. The program just closes down without a pronblem. It appears that Delphi 7 must embed some code to free the memory used up by dyanaic arrays.  

I notice that Delphi 2005 says that it is targetted to XP as well as to Server 2003. I wonder if I should complie my application under Delphi 2005.

Question by:YousefEisa
    LVL 17

    Assisted Solution

    with dynamic array's it's just SetLength(MyArray, 0);
    have you made sure all other events/threads are closed also? e.g. timer1.enabled := false;
    LVL 20

    Expert Comment

    Delphi 7 is fully compatible with 2003. The problem must be with your code. Generally you don't need to finalize dynamic arrays. Delphi does it for you. And even if it wouldn't, Windows would in the end also do it for you.

    Make sure you have stopped all threads (as TheRealLoki already said) before letting your app shut down.

    Author Comment

    Thanks guys for the quick response.
    My program is single threaded and i do not use timers. some dynamic arrays are global and stay active until the propgram ends. Other dynamic arrays are created within procedures but I close them before the procedures finishes.

    I use setlength a lot dealing with strings to dynamically change their size. I am assuming that I do not have to wory about these as they are initially defined as string variables within functions or procedures.

    But what is puzzling is that if there is something wrong with my code, why does the program behave well on XP, and gives me an error when running on Windows Server? Is XP more tolerant?
    LVL 20

    Accepted Solution

    There's no basic difference between XP and Windows 2003 Server. They're even running more or less the same kernel! Probably it's just random that it crashes on one PC but not on the other. It might also happen, that it will crash on another XP PC, but not on a 2nd 2003 Server PC.

    Have you tried madExcept yet?

    Featured Post

    IT, Stop Being Called Into Every Meeting

    Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

    Join & Write a Comment

    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…
    Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
    Need more eyes on your posted question? Go ahead and follow the quick steps in this video to learn how to Request Attention to your question. *Log into your Experts Exchange account *Find the question you want to Request Attention for *Go to the e…
    how to add IIS SMTP to handle application/Scanner relays into office 365.

    754 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

    19 Experts available now in Live!

    Get 1:1 Help Now