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 7766727
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T15:29:41+00:00 2026-06-01T15:29:41+00:00

For instance I have a method SomeMethod(Graphics g) { … } If I will

  • 0

For instance I have a method

SomeMethod(Graphics g)
{
    ...
}

If I will call this method in a manner

SomeMethod(new Graphics())

Will my graphics object be autodisposed or I should call g.Dispose() manually in the end of the method?

SomeMethod(Graphics g)
{
    ...
    g.Dispose();
}
  • 1 1 Answer
  • 0 Views
  • 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-06-01T15:29:42+00:00Added an answer on June 1, 2026 at 3:29 pm

    Disposable objects will not get autodisposed (the closest they can get to that is implementing a Finalizer that calls Dispose if necessary). You have to do this manually by calling Dispose() or by using it with a using block.

    If you want to auto dispose the object, you could do this:

    using (var g = new Graphics()) {
        SomeMethod(g);
    }
    

    The using block ensures that the Dispose() method is called automatically as soon as the block ends (so in this case, after SomeMethod returns or throws an exception).

    Note: You should dispose the object at the location near where you created it, if possible. Taking in a valid object and disposing of it inside the method could cause confusion.

    Graphics and probably most if not all BCL classes implementing this interface will also call Dispose() when the Finalizer is called. This is part of a proper implementation of IDisposable. However you never know when the finalizer is called and you should not rely on this implementation detail if you need your object to be deterministically disposed of.

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

Sidebar

Related Questions

I have a method where I would like to return an object instance of
I have a seed object which has an instance method seed:fall() which is called
If I mock a method to return a new instance of some object, how
I have a method that calls a service to retrieve an instance of an
In java can an instance variable and a method have the same name without
If I have for example a class with instance method and variables class Foo
For instance I have a string like this : abc123[*]xyz[#]098[~]f9e [*] , [#] and
I need to mock a GrailsControllerClass interface. Instance should have a static variable defined.
I have a method that takes an object as an argument. Both the caller
For instance: I have a purchased a hosting that allows me 10 GB's of

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.