© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
C#C
C#•4y ago•
8 replies
Sal

❔ Destroy objects in CSharp, IDisposable

Hi,
I am trying to get an object destroyed but it doesn't seem to be working.
I implemented IDisposable interface and started by just adding the
Dispose()
Dispose()
method, without any "destruction" I tried as they show on the documentation (simplified as far as I understand).
bool disposed
public void Dispose()
{
    Dispose(true);
    GC.SuppressFinalize(this);
}

private void Dispose(bool disposing)
{
    if (disposed)
        return;
}
bool disposed
public void Dispose()
{
    Dispose(true);
    GC.SuppressFinalize(this);
}

private void Dispose(bool disposing)
{
    if (disposed)
        return;
}


I also did use the
using (var obj = new MyObject())
{
  //some code
}
//check for obj
using (var obj = new MyObject())
{
  //some code
}
//check for obj

and when I checked for the object it was there still

any help with this?
C# banner
C#Join
We are a programming server aimed at coders discussing everything related to C# (CSharp) and .NET.
61,871Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements

Similar Threads

❔ When does the IDisposable objects gets automatically disposed ?
C#CC# / help
4y ago
Using IDisposable in private field
C#CC# / help
12mo ago
❔ deserialize in csharp
C#CC# / help
4y ago
✅ how to destroy game objects with three clicks
C#CC# / help
3y ago