[fpc-pascal] Object instance is suddenly corrupt or of unknown type?

JoshyFun joshyfun at gmail.com
Thu Oct 8 13:36:25 CEST 2009


Hello FPC-Pascal,

Thursday, October 8, 2009, 12:38:20 PM, you wrote:

GG>   Most of the times te watch output is:    FLayout:    TRichTextLayout 0xabcedef
GG> This is correct. The type is known and the memory address seems fine.
GG> (ignore my fake mem address above).
GG> But then at some point the watch output changes to:   FLayout:  ???   0xabcedef
GG> This is to be the problem! I can't seem to find out what cause the
GG> type to be unknown!! :-(  My Access Violation, is because I checked if
GG> FLayout is assigned (which is true even with unknown type) and then
GG> try and Free it, which throws the AV.

From my experience this happends in two cases usually:

1) You free the memory of the class (.free) directly or using another
variable which is referencing the same object. Something like:

  A:=XXX.Create();
  B:=A;
  [...Many lines of code...]
  B.Free;
  [...Many lines of code...]
  A.Free; //Crash...

2) Other more hard to detect is memory overwrite, so set all pascal
runtime checks on. It happends in something like this:

  A: array [0..9] of char;
  B: TMyClass;
  C: String;
  [...Many lines of code...]
  C:='This are more than 10 chars';
  Move(C[1],A[0],Length(C));
  B.Free; //Crash...

This will not be detected by runtime checks and I think it will not
also detected by heaptrc memory verifications. So take a look over the
prior declared variables, specially is they are arrays. As you are
running linux valgrind should help you.

-- 
Best regards,
 JoshyFun




More information about the fpc-pascal mailing list