[fpc-pascal]Constructor failing...

Peter Vreman peter at freepascal.org
Thu Mar 20 09:27:35 CET 2003


>>
>> > Hi again -
>> >
>> > another question; what is the best way to "fail" a constructor call?
>> For
>> > example, I have a constructor "timage.loadimage()", and I want it to
>> > return
>> > "nil" if it encounters a problem (e.g. the file name doesn't exist).
>> My
>>
>> Use fail :-)
>
> But, when I use fail in my simple example program, it returns NIL okay but
> the Heaptrace function tells me I have two unfreed memory blocks (36
> bytes).
> I can't see a memory leak anywhere else in that program, what could cause
> this? (Heaptrace output is as follows: I am using FPC 1.0.6 btw)
>
> Heap dump by heaptrc unit
> 13 memory blocks allocated : 224/248
> 11 memory blocks freed     : 188/208
> 2 unfreed memory blocks : 36
> True heap size : 20000000 (64 used in System startup)
> True free heap : 19999792
> Should be : 19999800
> Call trace for block 0x0040AEA4 size 24
>   0x004051AF
>   0x00401ECC  MYTESTCLASS__CREATE,  line 13 of
> e:/projects/tests/classtst.pp
>   0x00401DC6  main,  line 26 of e:/projects/tests/classtst.pp
>   0x00401059
> Call trace for block 0x0040AEF4 size 12
>   0x00405176
>   0x00401ECC  MYTESTCLASS__CREATE,  line 13 of
> e:/projects/tests/classtst.pp
>   0x00401DC6  main,  line 26 of e:/projects/tests/classtst.pp
>   0x00401059

That is the exception frame that is left on the heap. I don't have the
time to analyze what the cause is that the exception frame is not removed.






More information about the fpc-pascal mailing list