[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

memory leak in Delphi2.01 with basic functions

Posted on 1997-06-26
2
Medium Priority
?
377 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

What’s Wrong with Your Cloud Strategy ?

Even as many CIOs are embracing a cloud-first strategy, the reality is that moving to the cloud is a lengthy process and the end-state is likely to be a blend of multiple clouds—public and private. Learn why multicloud solutions matter in this webinar by Nimble Storage.

Question has a verified solution.

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

Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
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…
Are you ready to place your question in front of subject-matter experts for more timely responses? With the release of Priority Question, Premium Members, Team Accounts and Qualified Experts can now identify the emergent level of their issue, signal…
Suggested Courses

650 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