Home   |   Asp.Net 2.0   |   .Net Framework 2.0   |   IIS 6.0   |   Sql Server 2005   |   Visual Basic 2005   |   c# 2005   |   VS 2005   |   Visual Source Safe 2005

MS Dynamics CRM 3.0

SharePoint Portal Server 2003
SharePoint Server 2007
Dynamics NAV
Dynamics CRM
SharePoint Designer 2007
SharePoint Portal Server 2001
Windows SharePoint Services
Windows SharePoint Services 3.0
Project Server 2003
Project Server 2007
Dynamics – Point of Sale
Dynamics AX
Dynamics GP
Dynamics Retail Management System (RMS)
Dynamics SL
SQL Server 2000
Visual Basic .NET 2003
Visual C# .NET 2003
Visual C++ .NET 2003
Visual C++ 2005
Visual SourceSafe 6.0
Windows Server 2003
Windows Server 2003
Outlook 2003
ADO.NET 1.1
ASP.NET 1.0
Visual Studio Team Foundation Server
Visual Studio 2005 Team Edition
Windows Internet Explorer 7
BizTalk Server 2000
BizTalk Server 2002
BizTalk Server 2004
BizTalk Server 2006
Visual Studio 6.0
Access 2000
Access 2002
Access 2003
Access 2007
Access 97
Collaboration Data Objects 2.0
Commerce Server 2002
Content Management Server 2001
Commerce Server 2007
Content Management Server 2002
Data Access Components 2.7
Data Access Components 2.8
DirectX 9.0b
Office Small Business Accounting 2006
Accounting 2007
ActiveSync 4.1
Class Server 2.0
Groove 2007
Windows Vista
Outlook 2007
OneNote 2003
OneNote 2007
Office X for Mac
Zune software
Zune Live
Zoo Tycoon 2
Flight Simulator 2002
Dungeon Siege II

Cervo Technologies
The Right Source to Outsource

Oracle Database FAQS

Sharepoint Portal Server KB

Outlook 2007 Knowledge Base Articles

Visual Basic 2005 Knowledge Base Articles

Memory usage increases when you run a Visual Basic 2005 application that creates an instance of a class


Consider the following scenario:
You create a Microsoft Visual Basic application in Microsoft Visual Studio 2005.
The Visual Basic application contains a class.
The class contains an event.
The Visual Basic application creates an instance of the class.
You compile the Visual Basic application in debug mode.
In this scenario, when you run the Visual Basic application, memory usage increases.

Note You are more likely to notice this behavior when the following conditions are true:
The Visual Basic application runs continuously for a long time.
The Visual Basic application creates many instances of the class that contains an event. For example, the Visual Basic application contains a loop that creates multiple instances of the class.

CAUSE

This issue occurs because the Edit and Continue debugging feature in Visual Studio 2005 maintains a list of weak references to objects that have been created. If the object that has been created is a class that contains an event, these weak references are maintained for the duration of the program. This behavior increases memory usage.

RESOLUTION

To resolve this issue, use either of the following methods.

Method 1: Restart the Visual Basic application

You can restart the Visual Basic application. When you do this, the memory is freed.

Method 2: Compile the Visual Basic application in release mode

You can compile the Visual Basic application in release mode. When you run a Visual Basic application that was compiled in release mode, memory usage does not increase when you create an instance of a class that contains an event.

MORE INFORMATION

Steps to reproduce the issue

1.Start Visual Studio 2005.
2.On the File menu, point to New, and then click Project.
3.Under Project types, click Visual Basic. If you cannot see the Visual Basic project type, expand Other Languages, and then click Visual Basic.
4.Under Templates, click Console Application.
5.Type a project name, and then click OK.
6.Replace all the code in the Code window with the following code.
Module Module1

  Private Sub CreateClassWithEvent()
    Dim myClass As New CLeak
  End Sub

  Sub Main()               
    ' This loop infinitely creates a class that contains an event.
    While True
      CreateClassWithEvent()
      System.GC.Collect()
      System.GC.WaitForPendingFinalizers()
      Threading.Thread.Sleep(50)
    End While
  End Sub

End Module

Class CLeak
  Event myEvent()
End Class
7.On the Debug menu, click Start Debugging.


APPLIES TO
Microsoft Visual Studio 2005 Team System Architect Edition
Microsoft Visual Studio 2005 Team System Developer Edition
Microsoft Visual Studio 2005 Team System Test Edition
Microsoft Visual Studio 2005 Team Foundation
Microsoft Visual Studio 2005 Standard Edition
Microsoft Visual Studio 2005 Professional Edition
Microsoft Visual Studio 2005 Express Edition
Microsoft Visual Basic 2005

Keywords: 
kbtshoot kbprb KB919481

Copyright © 2004 - 2007 Gridview.org, Inc. All rights reserved. Powered by Smart Web Content Management System