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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T12:29:26+00:00 2026-05-24T12:29:26+00:00

There are a lot of questions on SO lamenting the fact that Code Analysis

  • 0

There are a lot of questions on SO lamenting the fact that Code Analysis rule CA2000 is being applied possibly too rigorously by VS2010, but I seem to have run into a case where it should be applied, but isn’t.

Consider the following code:

Image srcImage = Image.FromFile(source);
Bitmap newImage = new Bitmap(newWidth, newHeight);

using (Graphics gr = Graphics.FromImage(newImage))
{
    gr.DrawImage(srcImage, new Rectangle(0, 0, newWidth, newHeight));
}
newImage.Save(destination, ImageFormat.Jpeg);

Now if I run Code Analysis in Visual Studio 2010 on this, it will complain about newImage not being disposed (easy fix, put it in another using block), but it doesn’t complain about srcImage (which also has a Dispose() method that I’m never calling). Does anyone know why Code Analysis doesn’t complain here?

  • 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-05-24T12:29:27+00:00Added an answer on May 24, 2026 at 12:29 pm

    Well it should “complain about srcImage” too, however I guess that it doesn’t complain about it because you are passing it to the DrawImage method “gr.DrawImage(srcImage, new Rectangle(0, 0, newWidth, newHeight));“, So either it is not smart enough to know that it will not being used for more actions after the method returned, or maybe it assumed that you used it in gr instance that will be disposed. Anyway you should use using for srcImage just like what you are doing with newImage and don’t follow the Code Analysis on that.

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

Sidebar

Related Questions

There are a lot of questions about formatting forms so that labels align, and
I know there are LOT of questions like that but I can't find one
I know that there are a lot of questions and answers exactly about this
There are a lot of questions that ask about 'UNIX timestamp to MySQL time'.
There are a lot of questions about binding future manipulations to non-existent elements that
There are a lot of questions on this on here, but none that answer
I realize that there are a lot of questions regarding friend classes in C++.
I know that there are a lot of questions somewhat related to this one,
There are a lot of questions about didRegisterForRemoteNotificationsWithDeviceToken but they all sidestep a very
There's a lot of questions about bookmarks but none of them answers my question:

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.