473,324 Members | 2,178 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,324 software developers and data experts.

Object destroying problem...

Hello everybody!

I wrote an project with one class (Class) and two forms (Form1, Form2):

-----------------------------------Form2AndClass1Begin----------------------
------------------
public class Class
{
public void Form2_Closed(object sender, System.EventArgs e)
{
((Form2)sender).Closed -= new System.EventHandler(Form2_Closed);
}
~Class()
{
System.Windows.Forms.MessageBox.Show("~Class destroyed");
}
}

public class Form2 : System.Windows.Forms.Form
{
.....
}

-----------------------------------Form2AndClass1End------------------------
----------------

and application form Form1:

-----------------------------------Form1Begin-------------------------------
---------
public class Form1 : System.Windows.Forms.Form
{
private System.Windows.Forms.Button button1;
....
private void button1_Click(object sender, System.EventArgs e)
{
Form2 frm = new Form2();
Class cls = new Class();
frm.Closed += new System.EventHandler(cls.Form2_Closed);
frm.Show();
frm = null;
cls = null;
}
[STAThread]
static void Main()
{
System.Windows.Forms.Application.Run(new Form1());
}
}
}
-----------------------------------Form1End---------------------------------
-------

After Application starts and I Click on button1, then close Form2, then
objects Form2 and Class1 must be disposed and destroyed automatically
(project don't have any reference on its at this time!!!)??!!

Say me, please, why objects Form2 and Class1 destroyed periodically - from
time to time??

--
thank in avanced,
WBR, Roman S. Golubin

PS: I sorry for my bad english. Really sorry ;-(


Nov 15 '05 #1
1 1242
100

Hi, Roman
After Application starts and I Click on button1, then close Form2, then
objects Form2 and Class1 must be disposed and destroyed automatically
(project don't have any reference on its at this time!!!)??!!

Say me, please, why objects Form2 and Class1 destroyed periodically - from
time to time??


It takes time until GC collects the non-referenced objects. In your case it
will take even 2 passes until the memory gets reclaimed.
In the first pass Class1 finalizer will be called and at this point Form1
and Class1 will become ready for garbage collecting. The actual collection
will take place during the second pass.
If you try this in a simple test project GC may not occur unless you close
the application.

HTH
B\rgds
100
Nov 15 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Pete | last post by:
I have a site which is using sessions to pass data from one page through to the next. The problem that I have is that there are only two places where the session could/should be destroyed. This...
3
by: Virendra Verma | last post by:
This sounds weird, but I am looking for separate behaviors for destruction of a const and non-const object. I am trying to develop a smart/auto pointer class for writing objects to disk...
1
by: ibm | last post by:
I am running a simple test /*******CODE************/ class A { int _x; public: A(int i) { _x = i;
3
by: Steve Lutz | last post by:
Hi All, I have a Windows Service that runs well. The service hosts a remote object. The purpose of the object is so that I can "peak" into the service to see what it's doing. I wrote a small...
1
by: s.hong | last post by:
Hello, On my project, I have a problem that the Application object is destroyed suddenly. I hope to know how can I monitor the ASP.NET to catch the time of Application object destroying. ...
3
by: BakelNB | last post by:
I am new to the .Net environment, so please bear with me. I am passing a form object (e.g. formA) to an existing form (e.g. formB) by setting a property value defined in formB to hold the formA...
6
by: gamehack | last post by:
Hi all, Let me first start off with this piece of code: for(int i = 0; i < NumBoxes; ++i) { Box b(i, start, money, false); this->boxes.push_back(b);
5
by: Frederick Gotham | last post by:
If we have a simple class such as follows: #include <string> struct MyStruct { std::string member; MyStruct(unsigned const i) {
1
by: meannc | last post by:
Hi, I am creating a simple paint editor which user can draw lines and shapes on the browser. I followed the codes from a website VML Vector Graphics using the method "DrawImage()" . But I don't know...
3
by: =?Utf-8?B?QmFycnkgR2lsYmVydA==?= | last post by:
I have a class that raises events that downstream objects subscribe to. In one case, after destroying the object, the event seems to still get handled in a subscriber object. So I instantiate an...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.