?
Solved

memory leak in Delphi2.01 with basic functions

Posted on 1997-06-26
2
Medium Priority
?
374 Views
Last Modified: 2008-03-10
Hi,

I read some stuff in the delphis newsgroups about memory leak. Some deals with
database access, some other with VCL.

I meet today memory leaks with basic functions like "IntToStr" used in a console application on NT4. And also with Win32 API such as "GlobalGetAtomName", ...
Does anyone else also experimented such behaviour? If yes, what can we do to work around? Buy Delphi3 (if it corrects these problems)?

Thanks in advance

laurent


ps:
Below is a little program to test this, in which I use the GetHeapStatus to get info about memory:

var
  heapAfter   : THeapStatus;

begin
  writeln('before inttostr(23)');
  GetHeapStatus(heapAfter);
  MemoryDisplay(heapAfter);  // this just displays the THeapStatus fields in a formatted way

  inttostr(23);
  GetHeapStatus(heapAfter);
  writeln('after inttostr(23), before intostr(235465)');
  MemoryDisplay(heapAfter);

  inttostr(235465);
  GetHeapStatus(heapAfter);
  writeln('after intostr(235465), before intostr(243445343)');
  MemoryDisplay(heapAfter);

  inttostr(243445343);
  GetHeapStatus(heapAfter);
  writeln('after intostr(243445343)');
  MemoryDisplay(heapAfter);
end;

The result is as follow:

before inttostr(23)
TotalAddrSpace: 1048576  TotalUncommitted: 1032192  TotalCommitted: 16384  TotalAllocated: 768  TotalFree: 15428  FreeSmall: 84  FreeBig: 15344  Unused: 0  Overhead: 188  HeapErrorCode: 0

after inttostr(23), before intostr(235465)
TotalAddrSpace: 1048576  TotalUncommitted: 1032192  TotalCommitted: 16384  TotalAllocated: 780  TotalFree: 15412  FreeSmall: 84  FreeBig: 15328  Unused: 0  Overhead: 192  HeapErrorCode: 0

after intostr(235465), before intostr(243445343)
TotalAddrSpace: 1048576  TotalUncommitted: 1032192  TotalCommitted: 16384  TotalAllocated: 784  TotalFree: 15408  FreeSmall: 100  FreeBig: 15308  Unused: 0  Overhead: 192  HeapErrorCode: 0

after intostr(243445343)
TotalAddrSpace: 1048576  TotalUncommitted: 1032192  TotalCommitted: 16384  TotalAllocated: 788  TotalFree: 15404  FreeSmall: 120  FreeBig: 15284  Unused: 0  Overhead: 192  HeapErrorCode: 0


So the TotalAllocated takes up 12 bytes for the IntToStr function with a small integer value. Then using it again with a larger integer value takes another 4 bytes, and when using it with an even bigger value takes another 4.
0
Comment
Question by:poupou
[X]
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
2 Comments
 
LVL 3

Accepted Solution

by:
sperling earned 50 total points
ID: 1337834
This is not a leak, this is just a side-effect of delphi's long string handling. Try putting the above code in another procedure. Then display TotalAllocated before and after a call to the procedure, and you'll see that the amount of allocated memory is the same. Also, try with a loop performing e.g. 10000 IntToStr on a random value, and you will se a very low difference in total allocated memory before and after the loop. Again, when the procedure exits, that memory is automatically deallocated.

If this was a leak, the memory indirectly allocated by IntToStr would never have been freed. As exiting the procedure frees it, it is not a leak.

Regards,

Erik.

0
 

Author Comment

by:poupou
ID: 1337835
Sorry Erik, but putting the IntToStr code into a procedure and checking TotalAllocated before and after it does not change anything.
Even with the latest system.dcu download from Borland.
At least its true that the memory "leak" do not grow with the number of calls to that function.

Another guy told me the memory was released after some time. And its true that the memory is released after some time (but not only after a call to the sleep function !).
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
NetCrunch network monitor is a highly extensive platform for network monitoring and alert generation. In this video you'll see a live demo of NetCrunch with most notable features explained in a walk-through manner. You'll also get to know the philos…
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…
Suggested Courses
Course of the Month10 days, 10 hours left to enroll

764 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