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
O

objarni

@objarni
About
Posts
2
Topics
0
Shares
0
Groups
0
Followers
0
Following
0

Posts

Recent Best Controversial

  • another preference question....
    O objarni

    Leslie Sanford wrote:

    So what you're saying is that the garbage collector will call Dispose() in any case?

    It will if a Dispose() call is placed in the Finalizer/destructor of the class (~DatabaseConnection in my case..) -- and that is the case if you follow the NET documentation pattern for implementing IDisposable:

    public class SomeClass : IDisposable
    {
    ~SomeClass()
    {
    Dispose(false);
    }
    ...

    .. so if you've followed that pattern, forgetting some Dispose() (or using-clauses equivalently) calls would not be that dramatic for your application. BUT: I'm still not 100% clear on the low-level semantics of GC/Dispose in .NET. Below is a link to a long technical discussion I'm reading up on just to be sure what I've said is correct. Otherwise, I have quite a lot of things to do next week at work ;) : http://www.thescripts.com/forum/thread214497.html A link within that discussion points to a "morale" of why/how Dispose came about, really interesting read. Apparently it's written by one of the original .NET designers: http://discuss.develop.com/archives/wa.exe?A2=ind0010A&L=DOTNET&P=R28572 -- modified at 15:26 Friday 10th August, 2007

    The Lounge question c++ design collaboration performance

  • another preference question....
    O objarni

    Leslie Sanford wrote:

    Regarding destructors, I program mainly with C# now, and I miss the deterministic and automatic destruction mechanism of C++. Instead, I must remember to call Dispose where it is implemented.

    A little of topic, but I thought it was worth mentioning; Well -- Dispose() will be called by the garbage collector in any case -- so you don't really need to call it, unless you REALLY want to control the timing of the cleaning up of you resource. If I have such a scarce resource, say a database connection, that I really want to be cleaned up right now and not "in a couple of seconds", I use the C# keyword "using" this way: using(DatabaseConnection conn = DatabaseConnection.CreateInstance()) { ... } .. which automatically calls the Dispose() method of conn when exiting the code block {...} . Note that using() requires the declared object (conn here) to implement the IDisposable() interface. Even if I skipped the using() clause, conn.Dispose() would have been called when the garbage collector "thrashed" the conn some seconds later: DatabaseConnection conn = DatabaseConnection.CreateInstance(); ...

    The Lounge question c++ design collaboration performance
  • Login

  • Don't have an account? Register

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