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

x
?
Solved

Memory leak that is driving me nuts...

Posted on 2014-02-12
7
Medium Priority
?
398 Views
Last Modified: 2014-02-13
Hi Experts, I have my app fitted with FastMM4 to show me the memory leaks... and I've got one that's really stumping me. Basically I enter a procedure where I declare one local instance of a variable of type TCSVBasicRecord. Let's call this instance "NewItem". TCSVBasicRecord is previously declared globally in my app as such:

type TCSVBasicRecord = class(TObject)
  public
    Fields: TStringList; // de-quoted
    OriginalTexts: TStringList; // including quotes/double quotes
    Constructor Create;
    Destructor Destroy; override;

    Class Function CreateFromFileText(var AllText: string; delimiter_: char; quoteChar_: char; endOfRecordIndicator: string): TCSVBasicRecord;
end;

Open in new window


(the Function CreateFromFileText does a bunch of string manipulations and basically parses a string according to CSV convention... that's not the problem)

OK, in my procedure I've got a TRY...EXCEPT block within a While loop that does the bulk of the work. When data is clean and everything works good and no exceptions are thrown, everything gets freed and tidied up nicely and no memory leaks are reported when I exit my app. But when I run a test with erroneous data that triggers an exception and enters the EXCEPT block, I get a stupid memory leak. In my EXCEPT block, I show an error message and then terminate the app, but just before doing so, I make sure to perform the exact same free-ing of objects and closing of files that I do when the app runs successfully. So I'm just baffled by this... any thought anyone please?

Thanks
    Shawn
0
Comment
Question by:shawn857
[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
7 Comments
 

Author Comment

by:shawn857
ID: 39855176
Oh, by the way - here is the FastMM4 memory leak report that gets output:

This application has leaked memory. The small block leaks are (excluding expected leaks registered by pointer):



5 - 12 bytes: TCSVBasicRecord x 17, AnsiString x 40

13 - 20 bytes: TObjectList x 1, TList x 2

37 - 44 bytes: TSystemInfo x 1

45 - 52 bytes: TStringList x 34

53 - 60 bytes: AnsiString x 238

101 - 108 bytes: Unknown x 34

173 - 188 bytes: Unknown x 1


Note: To obtain a log file containing detail on memory leaks, enable the "FullDebugMode" and "LogMemoryLeakDetailToFile" conditional defines. To disable this memory leak check, undefine "EnableMemoryLeakReporting".
----------

That "TCSVBasicRecord x 17" is the culprit - all the other leaks reported are due to that one. I don't know how it would tally up 17 occurrences of TCSVBasicRecord leaking - I only declared one instance of it ("newItem") in my procedure... and I made sure I planted my erroneous data in the very first record the WHILE loop read. It's really got me scratching my head, for sure.

Thanks!
    Shawn
0
 
LVL 101

Expert Comment

by:mlmcc
ID: 39855202
I probably can't help with this but I know the experts who can will need to see the problem code to ensure you are freeing everything correctly.

mlmcc
0
 
LVL 31

Assisted Solution

by:Marco Gasi
Marco Gasi earned 668 total points
ID: 39855372
Yes, you should post here the code of the function CreateFromFileText();
0
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.

 
LVL 19

Accepted Solution

by:
MerijnB earned 668 total points
ID: 39855530
Do you still have the leak when you don't terminate the app, but close it 'normally'?
0
 
LVL 38

Assisted Solution

by:Geert Gruwez
Geert Gruwez earned 664 total points
ID: 39855613
are you sure you a class function for this ?
and not an ordinary method ?

the biggest possibility for your memory leak with class function is
that every you call this class function, it creates an instance of the object and doesn't free it
same like calling the constructor and not destroying the variable

are you creating an instance TCSVBasicRecord upon every call to the class function
or are you reading from an existing instance ?
0
 

Author Comment

by:shawn857
ID: 39857629
Merjin - no leak when I close my app normally - only when I purposely enter my exception code and I terminate it.
   I'm going to make a stripped-down version of my app and attempt to replicate the error so it will be more clear that way. Then I'll post the full code. I'll be back in a bit!

Thanks
   Shawn
0
 

Author Comment

by:shawn857
ID: 39857783
Well, as I was stripping it down, I found the problem boys - some other objects that I was failing to clean up during the terminate, that I would normally clean up during the normal program exit. Duhhh, sorry guys! I'm going to split the points amongst the 3 of you - Marco, Merjin and Geert. Thanks and sorry for the bother!

Shawn
0

Featured Post

[Webinar] Lessons on Recovering from Petya

Skyport is working hard to help customers recover from recent attacks, like the Petya worm. This work has brought to light some important lessons. New malware attacks like this can take down your entire environment. Learn from others mistakes on how to prevent Petya like worms.

Question has a verified solution.

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

Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
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 you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…
In a question here at Experts Exchange (https://www.experts-exchange.com/questions/29062564/Adobe-acrobat-reader-DC.html), a member asked how to create a signature in Adobe Acrobat Reader DC (the free Reader product, not the paid, full Acrobat produ…
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