Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / .NET Framework / Compact Framework / December 2007

Tip: Looking for answers? Try searching our database.

.NET Compact Framework System.Windows.Forms.UserControl is leaking memory

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Armin Sczuka - 23 Nov 2007 11:15 GMT
Hello,

I figured out that all objects based on System.Windows.Forms.UserControl are
never disposed by the Compact Framework GC. This problem occours only under
Windows CE not with Win32/ Win64.

Is this a known issue?

Is there any fix for it?

How about the .NET Compact Framework 3.5? Is it fixed there?

Thanks,
Armin
<ctacke/> - 23 Nov 2007 19:52 GMT
And you have a repro?  I've not heard of it as an issue and since the CF is
several years old, I'd suspect we'd have heard of someone having the problem
before now.

Signature

Chris Tacke, eMVP
Join the Embedded Developer Community
http://community.opennetcf.com

> Hello,
>
[quoted text clipped - 12 lines]
> Thanks,
> Armin
Armin Sczuka - 24 Nov 2007 13:31 GMT
Hi Chris,

if you create for example a new Console Application, add reference to System.Windows.Forms and run:

using System;
using System.Collections.Generic;
using System.Text;

namespace TestGC
{
class Good
{
 private byte[] _SomeData = new byte[1024];

 ~Good()
 {
 }
}

class Bad : System.Windows.Forms.Control
{
 private byte[] _SomeData = new byte[1024];
 
 ~Bad()
 {
 }
}

class Program
{
 static void Main(string[] args)
 {
  Good good;
  Bad bad;

  while (true)
  {
   good = new Good();
   bad = new Bad();

   System.Threading.Thread.Sleep(1);
  }
 }
}
}

If you run it an set a breakpoint on each finalizer you will see that the finalizer for Bad will never hit and the memory will go down (on your device).

Best Regards,
Armin

> And you have a repro?  I've not heard of it as an issue and since the CF is
> several years old, I'd suspect we'd have heard of someone having the problem
[quoted text clipped - 16 lines]
>> Thanks,
>> Armin
Peter Foot [MVP] - 26 Nov 2007 10:44 GMT
This is a Console app, can you repro it in a windows forms application?

Peter

Signature

Peter Foot
Microsoft Device Application Development MVP
www.peterfoot.net | www.inthehand.com
In The Hand Ltd - .NET Solutions for Mobility

 Hi Chris,

 if you create for example a new Console Application, add reference to System.Windows.Forms and run:

 using System;
 using System.Collections.Generic;
 using System.Text;

 namespace TestGC
 {
  class Good
  {
   private byte[] _SomeData = new byte[1024];

   ~Good()
   {
   }
  }

  class Bad : System.Windows.Forms.Control
  {
   private byte[] _SomeData = new byte[1024];
   
   ~Bad()
   {
   }
  }

  class Program
  {
   static void Main(string[] args)
   {
    Good good;
    Bad bad;

    while (true)
    {
     good = new Good();
     bad = new Bad();

     System.Threading.Thread.Sleep(1);
    }
   }
  }
 }

 If you run it an set a breakpoint on each finalizer you will see that the finalizer for Bad will never hit and the memory will go down (on your device).

 Best Regards,
 Armin

 "<ctacke/>" <ctacke[at]opennetcf[dot]com> wrote in message news:uZ1y2pgLIHA.4880@TK2MSFTNGP03.phx.gbl...
 > And you have a repro?  I've not heard of it as an issue and since the CF is
 > several years old, I'd suspect we'd have heard of someone having the problem
 > before now.
 >
 >
 > --
 >
 > Chris Tacke, eMVP
 > Join the Embedded Developer Community
 > http://community.opennetcf.com
 >
 >
 > "Armin Sczuka" <sczuka@newsgroup.nospam> wrote in message
 > news:OUy9pIcLIHA.1204@TK2MSFTNGP03.phx.gbl...
 >> Hello,
 >>
 >> I figured out that all objects based on System.Windows.Forms.UserControl
 >> are
 >> never disposed by the Compact Framework GC. This problem occours only
 >> under
 >> Windows CE not with Win32/ Win64.
 >>
 >> Is this a known issue?
 >>
 >> Is there any fix for it?
 >>
 >> How about the .NET Compact Framework 3.5? Is it fixed there?
 >>
 >> Thanks,
 >> Armin
 >>
 >>
 >>
 >
 >
Armin Sczuka - 26 Nov 2007 12:52 GMT
Yes Peter,

It's the same there. Actually the objects seams to be collected if you
manually call IDisposable.Dispose().

/Armin

> This is a Console app, can you repro it in a windows forms application?
>
> Peter
dbgrick - 26 Nov 2007 15:30 GMT
Armin,
You answered your own question.  Just like for forms, you controls, you must
call dispose for the control to be collected.  If you do not, then the
control will never be marked for collection.  As as test you can create a
form and then not call the dispose in the finally method, and you will see
the memory never be deallocated.  I've been called in on several projects
that were leaking memory and that is usually the reason for the leakage.

Regards,
Rick D.
Contractor

> Yes Peter,
>
[quoted text clipped - 6 lines]
> >
> > Peter
td - 28 Dec 2007 11:49 GMT
Hi,
I have just a question :
If my usercontrol contains controls, should I have to dispose all objects
before disposing my usercontrol ?
Thanks

> Armin,
> You answered your own question.  Just like for forms, you controls, you
[quoted text clipped - 19 lines]
>> >
>> > Peter
<ctacke/> - 28 Dec 2007 15:20 GMT
I would say yes, it's a good idea to do so.

Signature

Chris Tacke, eMVP
Join the Embedded Developer Community
http://community.opennetcf.com

> Hi,
> I have just a question :
[quoted text clipped - 27 lines]
>>> >
>>> > Peter

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.