Forum > General

Exceptions causing Memory Leaks?

(1/3) > >>

Zvoni:
Hi Folks,

ok, i'll bite. After searching and trying, and nothing helped, i'll ask finally.

Do i have to clean up an Exception?

Background:
I have some - Try - Except blocks

--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---Try//DoSomething with a Database which might cause an exceptionExceptOn Err:ESQLDatabaseError DoBeginWriteErrortologfile;End; I have zero Memory leaks, if i don't enter the Except-Fork
If the code enters the except-fork, i have 27 unfreed blocks
The HeapTrc-Output doesn't help much, because it points to the line/unit, from which that procedure was called.

Jonas Maebe:

--- Quote from: Zvoni on March 23, 2019, 04:02:40 pm ---Hi Folks,

ok, i'll bite. After searching and trying, and nothing helped, i'll ask finally.

Do i have to clean up an Exception?

Background:
I have some - Try - Except blocks

--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---Try//DoSomething with a Database which might cause an exceptionExceptOn Err:ESQLDatabaseError DoBeginWriteErrortologfile;End; I have zero Memory leaks, if i don't enter the Except-Fork
If the code enters the except-fork, i have 27 unfreed blocks
The HeapTrc-Output doesn't help much, because it points to the line/unit, from which that procedure was called.

--- End quote ---
You don't have to free up the exception itself, that happens automatically. However, the code that threw the exception may not have cleaned up everything before/when it threw the exception.

Zvoni:
*sigh*

i feared as much.....

Zvoni:
Have to reopen this one.
Scenario as follows:

In a library with exported flat functions.

Class1=MainThread
Class2=ChildThread
Class3=Database-Object
Class4=LogFile

Class1 creates Class2 which creates Class3, which creates Class4

The Exception occurs in Class 3, which i catch with a Try-Except (Class 3 is my "Representation" of a Database with all the Toys - Connection, Transaction, Query).
The Query creates the exception (an SQL-Statement checking if a table exists (SELECT * FROM UnknownTable) - If table unknown raise red flags)

What i don't understand: If everything is OK, no Memory leak and all objects are freed properly (otherwise i'd have leaks).
If the Exception occurs, i have a memory leak.
I've stepped through the whole code with no error, and even my Logfile shows proper chaining in freeing the objects.
All my procedure-calls transmit a result-message back to the start of the chain, which i evaluate, and if an error occured (like the Exception mentioned), i trigger the standard chain of destroying all objects (starting with class4, back to class 3, back to class 2, and finally back to class 1)
This standard-chain of freeing the objects is used, if everything went well! And there i have no leaks.

What am i missing?

EDIT: No Pointers at play. I use exactly one Pointer-Variable in my testing-project (Pointer to Record), which i dispose of after passing it to the library.
(Even tried setting it to nil inside the library. No difference, as well for the good result as well as the bad result)

Pascal:
HeapTrc should point you to the object(s) which have not been freed on exception.
That should give you a clue to what went wrong when exception is thrown.

Navigation

[0] Message Index

[#] Next page

Go to full version