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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T07:53:03+00:00 2026-05-23T07:53:03+00:00

I am saving a screenshot of current image on the computer: Rectangle bounds =

  • 0

I am saving a screenshot of current image on the computer:

Rectangle bounds = Screen.GetBounds(Point.Empty);

using (var bitmap = new Bitmap(bounds.Width, bounds.Height))
{
    using (Graphics g = Graphics.FromImage(bitmap))
    {
       g.CopyFromScreen(Point.Empty, Point.Empty, bounds.Size);
    }

    using (var mss = new MemoryStream())
    {
        bitmap.Save(mss,ImageFormat.Gif);
    }
}

And the memoryleak is at this code:

bitmap.Save(mss,ImageFormat.Gif);

Shouldn’t my use of using dispose everything I am using?

Why am I still getting really high memory usage when taking lots of pictures and the memory ain’t released back?

Thank you!

  • 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-23T07:53:04+00:00Added an answer on May 23, 2026 at 7:53 am

    You could try to use the BufferManager, it will manage Byte[] for you.

            // declare the BufferManager somewhere. Check thread safety!
            BufferManager bm = BufferManager.CreateBufferManager(qqq, yyy);
    
    
            // wrap your current code to use the buffer manager
            Rectangle bounds = Screen.GetBounds(Point.Empty);
    
            using (var bitmap = new Bitmap(bounds.Width, bounds.Height))
            {
                using (Graphics g = Graphics.FromImage(bitmap))
                {
                    g.CopyFromScreen(Point.Empty, Point.Empty, bounds.Size);
                }
    
                byte[] buffer = bm.TakeBuffer(yyy);
                try
                {
                  using (MemoryStream stream = new MemoryStream(buffer))
                  {
                     bitmap.Save(mss,ImageFormat.Gif);
                  }
                }
                finally
                {
                   bm.ReturnBuffer(buffer);
                }
           }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm saving by capturing screenshot via that code. Graphics Grf; Bitmap Ekran = new
After saving a String value into memcached using the Danga client, I attempted to
I'm having trouble saving a new row in the DataGridView back to the database.
I'm currently using the following code to produce an image whenever the user presses
I've been trying to code a simple screenshot application using rococoa (java to osx
In my Application,I am taking screenshots of image View and then I am saving
When saving an array in the userdefaults using the setObject method, is it then
I have a part of my app that has to save the current screenshot
On my screen there is an image and I have to save this image
I have code that makes a screenshot of the window using winapi. Then I

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.