.net - Test if a given object reference is valid -
how can reliably test (in il or methods provided .net) whether given native int
valid object reference (o
)? pointer may have been retrieved debugger, , might not valid (or collected after returned). returning object throws uncatchable executionengineexception
on invalid addresses. tried castclass
object
, throws nullpointerexception
in case of invalid references, throws bad accessviolationexception
addresses. there better way it, without throwing uncatchable exceptions or corrupting memory?
in comment on question, said pointer comes profiler api, i'm going assume debugger implemented using profiler api.
there no reliable way check if pointer object (objectid) valid. if pointing appears valid object, might not same object. instead, normal approach track object through gc callbacks , update/discard references appropriate.
if store pointer somewhere isn't updated , gc allowed run, should automatically assume pointer invalid.
Comments
Post a Comment