473,509 Members | 2,950 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

PageFile Usage increasing on every form change

3 New Member
Hi all,

I have developed a .Net app in MDI format. The problem that I have is that every time I change screens (New Child), the PC CPU PageFile usage increments a little. This happens until out of memory and I get a System.OutOfMemoryException.

Is there something subtle Im missing when opening/closing MDIChild forms?

I have written a sub to check that only 1 child is open at 1 time and close all child forms, before opening another:
Expand|Select|Wrap|Line Numbers
  1.  Public Sub CloseForms()
  2.  
  3.         Dim frm As Form
  4.         Dim Count As Integer
  5.         For Each frm In MDIParent1.MdiChildren
  6.             Count = Count + 1
  7.             frm.Dispose()
  8.         Next
  9.         frm = Nothing
  10.         Count = Nothing
  11.  
  12.     End Sub
  13.  
I also force a garbage collection with every child screen change:
System.GC.Collect()

I also wrote a sub to dispose of all controls on each screen every time a form closes:
Expand|Select|Wrap|Line Numbers
  1.  Private Sub frmMain_FormClosing(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
  2.         Dim FormObject As Control
  3.         For Each FormObject In Me.Controls
  4.             FormObject.Dispose()
  5.         Next
  6.     End Sub
Basically, I got nothing left in the tank, any suggestions would be well recieved!
Nov 15 '07 #1
2 1229
Shashi Sadasivan
1,435 Recognized Expert Top Contributor
instead of disposing each control,
if you rather do
Expand|Select|Wrap|Line Numbers
  1. Me.Dispose
it should do the same trick.

however you have put the code in form closing event.
I dont know if it makes any diference compared to if it was put in form_closed event
Nov 15 '07 #2
Plater
7,872 Recognized Expert Expert
The dispose method in a form is overloaded to go through all it's child controls and .dipose() them.
However, this doesn't apply to objects that are not gui controls.
Things like filehandles, io streams, sockets, threads and various other objects.
Those must be disposed/closed/aborted manually.
GC.Collect() will not neccesarily do it for you if there is an open handle to it (sockets,streams, etc) and threads run until their code exits or you call Abort() to send a ThreadAbortException
Nov 15 '07 #3

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

Similar topics

22
7393
by: Bryan Rickard | last post by:
I wrote a simple program in VB6 to copy all the files from a directory on a CD-ROM to my hard disk. There are about 10 files, each about 30MB. The program uses Get and Put to get data from the...
0
1184
by: KenH | last post by:
I have a MDI C# Windows form application that increases its memory usage about 4k every second - even with all of the child windows closed. I have seen other posts about similar problems,...
1
2362
by: marko | last post by:
Here is my problem. How can i make a field in a form change to a value 1 every morning when I turn access on, when the date changes? And how can i make a button on a form which would open another...
20
4193
by: Philip Carnstam | last post by:
How come .Net applications use so much memory? Every application I compile uses at least 10 MB of memory, even the ones consisting of only a form and nothing else. If I minimize them though the...
4
2422
by: Dan K. | last post by:
Hi NG, first of all i am new to OOP and C# so maybe thats my whole problem :) i wrote a small timer application, like i did if i was starting with programming in vb long time ago. the vb...
4
2498
by: Andrew Ward | last post by:
Hi All, I was wondering if it is possible to use precompiled headers without having to include a <stdafx.h> or whatever in every source file. My problem is that I have a project that makes heavy...
3
2525
by: tlyczko | last post by:
Hello, I've been reading about this topic, and I've gotten myself more confused, not less. We have a single-processor license SQL Server Standard 2005 (xeon 2.8 ghz) with 4 GB RAM in Windows...
7
12560
by: narpet | last post by:
Hello all... I'm having a problem moving my swap file to a drive other than my primary drive. Right now I have a 3+ gig pagefile.sys that resides on my C drive. When I try to reconfigure (through...
3
1323
by: chrispy102 | last post by:
Hi all, I have an MDI app developed using vis studio 2005. The problem I have is that evey time I close a Child form and open another, the CPU PF Usage increments slighty. This happens every time...
0
7136
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7344
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7412
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
7505
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5652
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
3203
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1570
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
775
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
441
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.