Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 1020597
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T11:11:11+00:00 2026-05-16T11:11:11+00:00

For too long I let the garbage collector do its magic, removing all responsibilities

  • 0

For too long I let the garbage collector do its magic, removing all responsibilities from my self.

Sadly it never turned into an issue… So I never gave a second thought to the subject.

Now when I think about it I don’t really understand what the “dispose” function really does and how and when it should be implemented.

The same question for finalize…

And a last question…
I have a class pictureManipulation : when I need to save/resize/change format … I start a new instance of that class use its objects and… well let the garbage collection kill the instance

class student
{
   public void displayStudentPic()
   {
      PictureManipulation pm = new PictureManipulation();
      this.studentPic = pm.loadStudentImage(id); 
   }
}

Class Test
{
  student a = new Student();
  a.displayStudentPic();
  // Now the function execution is ended... does the pm object is dead? Will the GC will kill it?
}
  • 1 1 Answer
  • 1 View
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T11:11:12+00:00Added an answer on May 16, 2026 at 11:11 am

    Regarding your class Student

    Do I need a Dispose() ?

    Assuming the Picture class is IDisposable: Yes. Because a Student object ‘owns’ the studentPic and that makes it responsible for cleaning it up. A minimal implementation:

    class Student : IDisposable
    {
       private PictureClass studentPic;
       public void Dispose()
       {
          if (studentPic != null)
            studentPic.Dispose();
       }
       ...
    }
    

    And you now use a Student object like:

    void Test
    {
      using (Student a = new Student())
      {
         a.displayStudentPic();    
      } // auto Dispose by using() 
    }
    

    If you can’t/don’t use a using(){} block, simply call a.Dispose(); when you’re done with it.

    But please note that the (far) better design here would be to avoid keeping a picture object inside your Student object. That sets off a whole chain of responsibilities.

    Do I need a Finalizer?

    No. Because when a Student object is being collected, its studentPic object is guaranteed to be collected in the same run. A Finalizer (destructor) would be pointless but still expensive.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

First of all forgive me, but the code was too long and copied from
Let me first tender my apologies for my question might be too long to
Okay, The post was getting way too long and contained way too much self
First, let me say that I have been at this for far too long,
my code is too long so sorry :) @model IEnumerable<Osos11.Models.Customers> @Html.DevExpress().GridView( settings => {
I just spent way too long trying to diagnose why, in the following snippet
It would take too long to explain why I need this, but I was
Since I got TLDR (too long didn't read) comments, I stripped 90% of this
Been at this far too long; trying to populate a field in a record
My server database took too long to run two sql queries by separate thread.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.