Re: Memory Leak?

Richard Blewett <[email protected]>
Newsgroups gmane.comp.windows.devel.dotnet.advanced
Message-ID <01e301c95450$62979d30$27c6d790$@com>
As an aside, I generally find the programming model introduced with SynchronizationContext in v2.0 to be simpler than using the Control.InvokeRequired/Control.BeginInvoke pair

Rich

> -----Original Message-----
> From: Discussion of advanced .NET topics. [mailto:ADVANCED-
> [email protected]] On Behalf Of Wilson, Phil
> Sent: 02 December 2008 01:27
> To: [email protected]
> Subject: Re: [ADVANCED-DOTNET] Memory Leak?
> 
> A wild guess: If your cross-thread problems were related to the thread
> wanting to change the UI, were you using Control.InvokeRequired and the
> cross-thread delegate call model?
> 
> Phil Wilson
> 
> 
> -----Original Message-----
> From: Discussion of advanced .NET topics. [mailto:ADVANCED-
> [email protected]] On Behalf Of Dave Vorgang
> Sent: Monday, December 01, 2008 4:00 PM
> To: [email protected]
> Subject: Re: [ADVANCED-DOTNET] Memory Leak?
> 
> My first go at this was to place it in a separate thread.  I spent
> about a week on it and could never get it to work correctly.  I kept
> get getting cross thread problems.
> 
> The concept seems pretty simple.  My main process brings up a form,
> changes certain attributes and initializes some fields, then the main
> process waits until the user presses the enter key or a function key.
> 
> I can't use a dialog box because I want the form to remain once the
> user press Enter or a function key, but I want the main process to
> continue.
> 
> So, I just need the ability wait until the user presses enter (or
> function key).
> 
> Any more suggestions would be helpful.
> 
> Dave Vorgang
> Senior Programmer / Analyst
> Medford School District - Information Technology
> (541) 842-1021
> mailto:[email protected]
> 
> 
> -----Original Message-----
> From: Discussion of advanced .NET topics. [mailto:ADVANCED-
> [email protected]] On Behalf Of Marc Brooks
> Sent: Monday, December 01, 2008 3:48 PM
> To: [email protected]
> Subject: Re: [ADVANCED-DOTNET] Memory Leak?
> 
> You should NEVER be calling GC.Collect.  For that matter, you really
> shouldn't ever code for DoEvents.  Rather, do whatever it is you need
> to do in a loop in a separate thread from the UI.  If I had more idea
> who was calling this method, and who was changing the global
> variables, then I could give better advice.
> 
> On Mon, Dec 1, 2008 at 17:43, Dave Vorgang
> <[email protected]> wrote:
> > I changed it to:
> >        Do
> >            System.Windows.Forms.Application.DoEvents()
> >            Thread.Sleep(55)
> >            GC.Collect()
> >        Loop Until _KeyEntered >= 0
> >
> > This helped but it still increased Mem Usage as time went on.
> >
> > Any help on fixing this would be greatly appreciated.
> >
> > Thanks,
> >
> > Dave Vorgang
> > Senior Programmer / Analyst
> > Medford School District - Information Technology
> > (541) 842-1021
> > mailto:[email protected]
> >
> > -----Original Message-----
> > From: Discussion of advanced .NET topics. [mailto:ADVANCED-
> [email protected]] On Behalf Of Mark Hurd
> > Sent: Monday, December 01, 2008 3:16 PM
> > To: [email protected]
> > Subject: Re: [ADVANCED-DOTNET] Memory Leak?
> >
> > On Tue, Dec 2, 2008 at 9:38 AM, Steve Johnson <[email protected]>
> wrote:
> >> Likely, the problem is recursion.  Each call to DoEvents pumps
> messages,
> >> which causes your VREADFIELDS function to be called from within
> itself.
> >> Each call allocates another stack frame.  You'll eventually run out
> of stack
> >> space and crash with a StackOverflowException.
> >
> > I agree that it is not due to the code sample provided in isolation.
> > Whenever we need an idle loop we use a similar loop (with Sleep(55)),
> > and when it is worth suggesting we know it would be a good time to do
> > a GC.Collect we include that too.
> >
> > Regards,
> > Mark Hurd, B.Sc.(Ma.)(Hons.)
> >
> > ===================================
> > View archives and manage your subscription(s) at
> http://peach.ease.lsoft.com/archives
> >
> > ===================================
> > View archives and manage your subscription(s) at
> http://peach.ease.lsoft.com/archives
> >
> 
> 
> 
> --
> Marc C. Brooks
> http://musingmarc.blogspot.com
> 
> NOT sent from an iPhone
> 
> ===================================
> View archives and manage your subscription(s) at
> http://peach.ease.lsoft.com/archives

===================================
View archives and manage your subscription(s) at http://peach.ease.lsoft.com/archives
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.