473,385 Members | 1,409 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,385 software developers and data experts.

Garbage Collection after calling and returning from 2nd form

6
Hi,
Just a quick question - what should I do for garbage collection after calling and returning from a class using a 2nd form? From what I have read the app will take care of it for me, but....

Any help appreciated!!

Regards,

TD
Mar 22 '10 #1
2 2808
GaryTexmo
1,501 Expert 1GB
For the most part, it will. Memory will get flagged to be garbage collected if there's no longer a reference to it, so as long as nothing in referencing any of your 2nd Form's memory, it will get cleaned up when the garbage collector decides it's an appropriate time.

Unless you are in a low memory environment or that 2nd form allocates a huge amount of memory and you're worried about your main form (or another form) not having enough after that 2nd form closes, you're probably fine to not worry about it. Let the garbage collector do it's job, supposedly it does it fairly well on a windows environment.

If you absolutely do need to clean up that memory, you can call GC.Collect() after your form closes. This can be a rather expensive operation though because not only will it do garbage collection on your own program, it will do it on any other managed program currently running. The result is you can inadvertently tie up your processor for an unknown period of time (depending on how much memory needs to be garbage collected). Additionally, I believe it will also interrupt the processing of those other managed programs.

As I've understood it, you shouldn't ever call GC.Collect()... but sometimes you have to :D There are also properties you can set on the garbage collector to increase the frequency of collection, or various other conditions for garbage collection. Have a read about the GC class...

http://msdn.microsoft.com/en-us/libr...8VS.80%29.aspx
Mar 22 '10 #2
TDHall
6
Thanks for the response. You pretty much confirmed what I thought, but it's nice to get some backup confirmation.

Regards,
TD
Mar 22 '10 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

14
by: Ă–mer KUL | last post by:
hi, i have a garbage collection problem. i have an application writen by vb.net, i am opening a form and in this form there is a big query. when i open the form, it takes 80 mb memory because of...
3
by: Ian Taite | last post by:
Hello, I'm exploring why one of my C# .NET apps has "high" memory usage, and whether I can reduce the memory usage. I have an app that wakes up and processes text files into a database...
34
by: Ville Voipio | last post by:
I would need to make some high-reliability software running on Linux in an embedded system. Performance (or lack of it) is not an issue, reliability is. The piece of software is rather simple,...
2
by: C P | last post by:
I'm coming from Delphi where I have to explicitly create and destroy instances of objects. I've been working through a C#/ASP.NET book, and many of the examples repeat the same SqlConnection,...
18
by: MuZZy | last post by:
Hi, I got a situation here :) an dwonder if someone can help me. I have an MDI app and say, the child form has a button, clicking on which calls a database transaction - grabbing a lot of tables...
3
by: Stephen Engle | last post by:
I have an app that I am working on that is dependent on an unmanaged code library. There is a middle library of managed C++ that encapsulates the unmanaged libary functions calls into a class. ...
6
by: Andy | last post by:
Along with many others I've noticed the large amount of memory that can be taken up by the aspnet_wp.exe. I've found that I can better control and limit this memory consumption by including a...
5
by: Ben | last post by:
Could someone please verify if what I am doing as follow is corrected: 1. when dealing with custom class objects: ..... public myObject as myClass myObject as New myClass .......here I am...
28
by: Goalie_Ca | last post by:
I have been reading (or at least googling) about the potential addition of optional garbage collection to C++0x. There are numerous myths and whatnot with very little detailed information. Will...
0
by: Kyle Lanclos | last post by:
I've done a lot of web searching, a fair bit of C-source reading, and quite a lot of miscellaneous head scratching, and I find that I am not necessarily closer to an ideal solution. I have a...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
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...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.