• Visitors can check out the Forum FAQ by clicking this link. You have to register before you can post: click the REGISTER link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below. View our Forum Privacy Policy.
  • Want to receive the latest contracting news and advice straight to your inbox? Sign up to the ContractorUK newsletter here. Every sign up will also be entered into a draw to WIN £100 Amazon vouchers!

.NET and destructors!!!!!!!!!!!!!

Collapse
X
  •  
  • Filter
  • Time
  • Show
Clear All
new posts

    .NET and destructors!!!!!!!!!!!!!


    #2
    Just use Java and get your garbage collected.

    Comment


      #3
      Originally posted by Jabberwocky
      Just use Java and get your garbage collected.
      Same as in .net. The garbage collector will decide when to call the destructor. At least, you can write one.

      .Net! The best! The future!
      I've seen much of the rest of the world. It is brutal and cruel and dark, Rome is the light.

      Comment


        #4
        Originally posted by Francko
        At least, you can write one.
        Does not mean you should

        Comment


          #5
          Originally posted by Francko
          Same as in .net. The garbage collector will decide when to call the destructor. At least, you can write one.
          You can in Java too. You override the finalize() method from the Object class. Though as in .NET, the garbage collector has a mind of its own and will garbage collect when it feels like it.
          Listen to my last album on Spotify

          Comment


            #6
            Our garbage collector comes round once a week. We have to put recyclables in the green bin.

            Comment


              #7
              And you have to move your object references to the end of yer driveway or else theyll be left there for days....

              Ok, I admit, its time to get out of IT...
              Vieze Oude Man

              Comment


                #8
                Originally posted by Fungus
                Our garbage collector comes round once a week. We have to put recyclables in the green bin.
                Except when they're on strike.

                I think I want my objects destroyed when I bloody well tell them to be destroyed.
                Will work inside IR35. Or for food.

                Comment


                  #9
                  Originally posted by VectraMan
                  I think I want my objects destroyed when I bloody well tell them to be destroyed.
                  You said it - I can agree with GC deciding when to collect garbage, however if I call GC.Collect() this means it MUST collect, or at least not to keep classes with destructors hanging for a long time - the funny thing is that happens only in SOME circumstances in .NET 1.1, but seems to happen full time in .NET 2.0

                  Originally posted by cswd
                  Make sure they implement IDisposable and stick them in using blocks.
                  Yes I started using IDisposable for a long time, but I also had destructor - this was the undoing as GC seems to have queued them for destruction in a separate thread that was taking AGES to execute under some circumstances that I managed to re-create.

                  Highly annoying memory "leak" was fixed by commenting out destructors, I mean this is BS! Can't always use "using" block since I need to have many objects that will self-destruct when needed.

                  Comment


                    #10
                    Originally posted by cswd
                    The object should have finished it's work when you've finished with it and released it for destruction. The only thing it should do is free the heap later (all stack stuff is freed during execution).
                    Which was exactly the problem - I had Dispose called for all objects, but they were not removed from heap because objects had consturctors, so GC in its wisdom thought to keep them around since it assumed that just because machine has got 2 GB of RAM its okay to eat 300 MB of it for no reason - crap GC design. If programmer explicitly calls GC.Collect() then GC should either collect garbage or new developer responsible for GC should be hired.

                    Originally posted by cswd
                    If that fails, stick 12Gb of memory in the machine (I've had to do this before!). Plenty of room for the GC to fill up.
                    I don't like solutions like this - this problem in GC was responsible for another strange memory leak that I had - starting at 300 MB but working its way to 1.5 GB until it run out of memory, effectively it seemed that GC stopped working

                    Comment

                    Working...
                    X