I have been running into errors where objects are somehow freed but we end up calling FreeMem on them. Of course this causes an error since the memory has already been freed and throws an error.
I know that a try-catch block would probably fix it but that's a lot of try-catch blocks. With the regular object.free the way to avoid this is FreeAndNil(object) but I can't find the equivalent for FreeMem. Something which tests whether it's allocated or not before freeing.
What's the best solution here in ease of reading, maintainability, and stability.