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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T01:45:19+00:00 2026-05-26T01:45:19+00:00

I try to get to grasp with Ants Memory Profiler. The problem I have

  • 0

I try to get to grasp with Ants Memory Profiler. The problem I have is that I dont have an easy application that has a memory leak.

I used the sample of Redgate (QueryBee), but it was to contreived for my taste. There has to be an easier app for that.

I tried to make one up but it is not working. It is not working means: I dont have a memory leak. I read about calling ShowDialog without disposing the called form would get me a memory leak, but thats not the case here.

I use VS2010 and .NET 4.0

I am especially interested in issues that are very common.

Here is what I have so far.Can you get me a memory leak?:

MainForm

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace MemoryLeakTest
{
    public partial class MainForm : Form
    {
        public MainForm()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            SubForm formToCall = new SubForm();
            formToCall.ShowDialog();
        }
    }
}

Subform

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Collections;

namespace MemoryLeakTest
{
    public partial class SubForm : Form
    {


        public SubForm()
        {
            InitializeComponent();
        }

        private void SubForm_Load(object sender, EventArgs e)
        {

            ArrayList persons = new ArrayList();

            for (int i = 0; i <= 50000; i++)
            {
                var person = new {
                    Name = "1 SchorschSchorschSchorschSchorschSchorschSchorschSchorschSchorschSchorschSchorschSchorschSchorschSchorsch",
                    LastName = "KluniKluniKluniKluniKluniKluniKluniKluniKluniKluniKluniKluniKluniKluniKluniKluniKluniKluniKluniKluni", 
                    Age = 50,
                    City = "LondonLondonLondonLondonLondonLondonLondonLondonLondonLondonLondonLondonLondonLondonLondonLondonLondonLondonLondonLondonLondon",
                    Zip = "223012230122301223012230122301223012230122301223012230122301223012230122301223012230122301223012230122301223012230122301223012230122301", 
                    Index = i 

                };
                persons.Add(person);
            }

            dataGridView1.DataSource = persons;
        }

        private void SubForm_FormClosed(object sender, FormClosedEventArgs e)
        {
            //this.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-05-26T01:45:20+00:00Added an answer on May 26, 2026 at 1:45 am

    Add this to your SubForm

    public void mouse_handler(object sender, MouseEventArgs e)
    {
    
    }
    

    And change the MainForm to do this

    private void button1_Click(object sender, EventArgs e)
    {
         SubForm formToCall = new SubForm();
         this.MouseClick += new MouseEventHandler(formToCall.mouse_handler);
         formToCall.ShowDialog();
    }
    

    Now it doesn’t matter if you .Dispose() the SubForm or not, you will still have a “leak”. Your MainForm keeps a reference to the SubForms indefinitely, through its mouse event handler, which is basically just a list of who is to receive the events, since that handler is never de-registered.

    Ants will help you track down this, but rather manually, it’ll show you objects still being alive and referenced from the root, and you have to discover that these objects should not referenced anywhere. I believe Ants also can generate warnings/etc. when it finds objects that have been .Disposed(), but are still referenced somewhere.

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

Sidebar

Related Questions

I have a function in Jquery, that try get html from an page: $.ajax({
I face a problem when I try to get value from primary table in
I have an monotouch application that includes an objective-c static library. The application runs
I'm learning and try to get a firm grasp of correctly implementing sound MVC
I write a java program that has a json parser to get some data.
I try get the mp3 flash player to work with my javascript on all
I try to get to a page straight from Bash at http://www.ocwconsortium.org/ . The
I try to get all WPF window controls collections. In other words i try
I try to get the name of executable name of all of my launched
I try to get the last modification date of a file: NSFileManager *fm =

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.