Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Use of GC.SuppressFinalize in ref counted objects

Use of GC.SuppressFinalize in ref counted objects

Scheduled Pinned Locked Moved C#
discussionagentic-airegex
1 Posts 1 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    molesworth
    wrote on last edited by
    #1

    Afternoon all, I'm looking for advice or opinions on the best placement of GC.SuppressFinalize for reference counted objects. The "standard" dispose pattern has the call in the public Dispose method :-

    public void Dispose()
    {
        Dispose(true);
        GC.SuppressFinalize(this);
    }
    

    However, for objects with reference counts I'm inclined to put it in the protected Dispose :-

    protected void Dispose(bool \_fulldispose)
    {
        if (!m\_Disposed)
        {
            if (RemoveRef() == 0)
            {
                if (\_fulldispose)
                {
                    GC.SuppressFinalize(this);
    
    etc...
    

    My reasoning is that if not all references are explicitly disposed, then the finaliser will still be needed to do the clean up. (Although in our system all objects with unmanaged components should be explicitly disposed, so that may be academic.) There are lots of discussions about Dispose, IDisposable, SuppressFinalize etc. out on the net, but very few deal with the ref counted situation, so I'm open to any thoughts or advice...

    There are three kinds of people in the world - those who can count and those who can't...

    1 Reply Last reply
    0
    Reply
    • Reply as topic
    Log in to reply
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes


    • Login

    • Don't have an account? Register

    • Login or register to search.
    • First post
      Last post
    0
    • Categories
    • Recent
    • Tags
    • Popular
    • World
    • Users
    • Groups