TObjectList.Clear Access Violation

I got confused by a very strange problem with a large application. I actively use TObjectList to store a custom object on them. On large lists, I experience strange crashes with "Access violation by address .. read address .." "privileged indication" and others when I use the CLEAR method. I made sure that this happens exactly when I try to delete the last item in the list. I checked this by registering the removal of the contained objects from their destroy proc, and also tried to delete them myself (for a: = olist.count-1 downto 0 do .. debugmsg ('deleting' + inttostr (a)) .. olist.delete (a)), in both cases I get an access violation when deleting the last remaining item in the list.

This is not always because I use clear in other areas, as well as several different (smaller) lists, but this happens at a very specific point in my application.

I don’t know what could be wrong, there is nothing trying to access the list during cleaning, and cointained objects do not have access to their parent list of objects in the TObjectList.delete / clear methods when it comes to clearing the last item.

Any suggestions? Using Delphi XE.

+7
source share
2 answers

It sounds like you are releasing objects that have already been freed. To track this, download the full version of FastMM , add FullDebugMode to the conditional definition line under "Project Settings" β†’ "Delphi Compiler" and "Map" File option in the "Setting Links" to "Details" section and rebuild. (Build, not compile.) Then copy the FullDebugMode DLL to the same folder as the EXE, and run it. It will monitor your memory during allocation and deallocation, and when you try to free the same object a second time, it will catch this and provide you with very detailed debugging information about where the problem came from.

+18
source

Are you sure that the last object is valid and not yet deleted? It may be listed twice, for example. due to other errors.

+1
source

All Articles