© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
C#C
C#•4y ago•
19 replies
Dusty

✅ Is managed pointer (ref) or raw pointer (void*) null?

How can I check if a managed pointer or raw pointer points to an already garbage collected address?

```cs
var sample = new Sample();
ref var refToSample = ref Unsafe.AsRef(in sample);

sample = null;

// How to check if sample got garbage collected?
// this is false
bool isNullRef = Unsafe.IsNullRef(ref refToSample);

// How to check if the value the pointer is pointing at is garbage collected?
void* ptr = Unsafe.AsPointer(ref refToSample);
C# banner
C#Join
We are a programming server aimed at coders discussing everything related to C# (CSharp) and .NET.
61,828Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements

Similar Threads

❔ null ref exception in logs
C#CC# / help
3y ago
❔ Raw Websockets, ref alternative in async programming
C#CC# / help
3y ago
with or without ref
C#CC# / help
3y ago
In String constructor `String(Char*)`, `Char*` is character pointer or character array pointer?
C#CC# / help
11mo ago