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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T00:22:42+00:00 2026-06-02T00:22:42+00:00

Using Visual C# 2008 Exp Edition, I’ve noticed that with my project loaded the

  • 0

Using Visual C# 2008 Exp Edition, I’ve noticed that with my project loaded the process is consuming ~70,000K of memory. After a few hours this builds up to about ~500,000K.

At this point a UserControl containing a PictureBox (within a Panel) shows a memory error in Visual C# Express. The picture box contains a bitmap and grid of rectangles, drawn with System.Drawing.Graphics.

Here’s the code:

This segement occurs just once when the UserControl is initialised.

Bitmap myBitmap = new Bitmap(a, b);
Graphics g = null;
g = Graphics.FromImage(myBitmap);
g.FillRectangle(Brushes.SteelBlue, 0, 0, c, d);

//Paint Rows & Columns
for (int x = 0; x <= e - 1; x++)
{
    for (int y = 0; y <= f - 1; y++)
    {
        g.DrawRectangle(Pens.LightBlue, g, h, i);
    }
}
//Release Resources
g.Dispose();
//Add bitmap with grid to BG
ScorePictureBox.Image = myBitmap;

This piece of code is quite frequent:

for (int EventIndex = 0; EventIndex <= MidiNoteDownArray.Length - 1; EventIndex++)
{
    //Paint notes to grid

    e.Graphics.FillRectangle(Brushes.LightBlue, j, k, l, m);
    e.Graphics.DrawRectangle(Pens.Purple, o, p, q, r);
}
e.Dispose();

Am I not releasing resources properly? How can I do this correctly?

  • 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-02T00:22:44+00:00Added an answer on June 2, 2026 at 12:22 am

    You’re not releasing your bitmap. Depending on how often your code runs the garbage collector may not be able to keep up.

    using (Bitmap myBitmap = new Bitmap(a, b))
    using (Graphics g = Graphics.FromImage(myBitmap)) {
        for (int x = 0; x <= e - 1; x++) {
            for (int y = 0; y <= f - 1; y++) {
                g.DrawRectangle(Pens.LightBlue, g, h, i);
            }
        }
    
        ScorePictureBox.Image = myBitmap;
    }
    

    You will want to check other parts of your code that use GDI for unreleased resources as well.

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

Sidebar

Related Questions

I'm using Visual Studio 2008 with a project that's targeting .NET 2.0. I need
Using Visual Studio 2008, I created a C++ Win32 project. To release the program,
Using visual studio 2008. When I add a new aspx form to a project
Using Visual Studio 2008 - I add a Setup project (from Setup and Deployment
Im using Visual studio 2008. Every once in a while files that exist in
I am using Visual Studio 2008 SP1 (version 9.0.30729.1). My problem is that the
Using Visual Studio 2008 and VB.Net: I have a working web app that uses
Using Visual Studio 2008: Within the Solution there is a main project (Project1), within
I'm using Visual Studio 2008 for a C# project; we're also using (company mandated)
I am using visual studio 2008 professional edition. In my solution I have about

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.