Jump to content
alogrep

My custom component becomes NI>

Recommended Posts

Hi,

I have a component with is derived from the Tcomponent class and is basically a table with cells. Each cells contains a text, a Tcolor and a TObject (which is always a TObject(integer).  Randomly I an AV error and when I check on the component, the component is NIL. I cannot trace back to where/what overwrote the memory. Madexcept does not catch the AV even with the buffer overrun checked. My endless Google search shows me lots of memory LEAKS but very little on memory overwrite. Anybody knows of a good tool that would help catch the overwrite excacly where and when it happens? Thanks 

Share this post


Link to post

Uhm. The error happened, but Fastmm4 tells me all about memory leaks, nothing about memory overwrite.

It shows a complete list of allocations for the table cells, and all allocations are shown as memory leaks because the table is  somehow overwritten (and becomes NIL), and therefore the Destructor is not called. It gives me no clue as to what function exactly overwrite the table. 

Share this post


Link to post
16 hours ago, alogrep said:

the table is  somehow overwritten (and becomes NIL), and therefore the Destructor is not called. It gives me no clue as to what function exactly overwrite the table. 

Run the component code in the debugger, and put a DATA BREAKPOINT on the pointer variable that is turning nil unexpectedly, and when the breakpoint is hit then look at the call stack to see who is setting the pointer to nil.

  • Like 1

Share this post


Link to post

Thanks Remy.

The tables are created, populated and freed dynamically.  Te component class is Tslim. Then according to what I need I do table1:=Tslim.Create; table2:=Tslim.create etc. Is it possible to put a  databreakpoint on a class as opposed to a variable? How?

Share this post


Link to post

Have you set the overflow and range checking in the project options?

Share this post


Link to post
2 hours ago, alogrep said:

table1:=Tslim.Create

You told as that a component is becoming nil. Nil can be a reference to an instance of a class (namely a variable), not a class itself.

If table1 is that component that is becoming nil then put a data breakpoint on table1. More exactly on table1's address (namely @table1). But it is enough to write table1 into the addresses field of "Add Data Breakpoint" dialog.

 

@Remy Lebeau thank you very match for this. I needed a data breakpoint sometimes but I didn't know they actually exists.

 

Edited by Cristian Peța

Share this post


Link to post

Where do you store reference variables for the tables? I.e. table1, table2 etc.

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×