Microsoft KB Archive/97136

= BUG: OLE DataText Prop Doesn't Free Memory When Object Closed =

Article ID: 97136

Article Last Modified on 1/8/2003

-

APPLIES TO


 * Microsoft Visual Basic 2.0 Professional Edition

-



This article was previously published under Q97136



SYMPTOMS
An OLE destination (OLE client) control (OLECLIEN.VBX) can send data to the OLE source (OLE server) application by setting the DataText property, however the memory allocated for this data is not released until OLECLIEN.VBX is unloaded. The memory is freed when you exit from the application.



STATUS
Microsoft has confirmed this to be a bug in the Professional Edition of Microsoft Visual Basic version 2.0 for Windows. We are researching this problem and will post new information here in the Microsoft Knowledge Base as it becomes available.



MORE INFORMATION
Each time an OLE destination object is created and the DataText property is set, a new private segment is allocated by OLECLIEN.VBX. When working in the VB.EXE interpreter environment, this segment is deallocated when you exit from VB.EXE or when you start a new project (ALT+F+N). A Visual Basic EXE program deallocates this segment when it is unloaded.

The following code uses Microsoft Graph as the OLE source application, but the memory leak also occurs if OLECLIEN.VBX is used with other OLE source programs.

To verify that the memory leak occurs, run the code listed below. Then load a tool like Heap Walker that ships with the Microsoft Windows Software Development Kit (SDK), and watch the number of private segments allocated to OLECLIENT change even after the code deletes the OLE objects.

Steps to Reproduce Problem
 Start Visual Basic or from the File menu, choose New Project (ALT, F, N) if Visual Basic is already running. Form1 is created by default. From the File menu, choose Add File. In the Files box, select the OLECLIEN.VBX custom control file. The OLE destination (client) tool appears in the Toolbox. Place an OLEClient control on Form1.  Enter the following code: Private Sub Form_Click Const OLE_CREATE_NEW = 0 Const OLE_UPDATE = 6 Const OLE_ACTIVATE = 7 Const OLE_CLOSE = 9 Const OLE_DELETE = 10

OleClient1.Class = &quot;MSGraph&quot; OleClient1.Protocol = &quot;StdFileEditing&quot; OleClient1.ServerType = 1 OleClient1.Action = OLE_CREATE_NEW OleClient1.Action = OLE_ACTIVATE OleClient1.Format = &quot;CF_TEXT&quot;  ' MS Graph accepted format

Title$ = &quot;This is a title&quot; & Chr$(10)

' The data for a graph Dim Tb As String ' tab character Tb = Chr$(9) GraphData$ = &quot;A&quot; & Tb & &quot;3&quot; & Tb & &quot;4&quot; & Tb & &quot;5&quot; & Chr$(10) GraphData2$ = &quot;B&quot; & Tb & &quot;9&quot; & Tb & &quot;2&quot; & Tb & &quot;4&quot; & Chr$(10)

' Cause a private segment in OLECLIEN to be allocated. OleClient1.DataText = Title$ & GraphData$ & GraphData2$

OleClient1.Action = OLE_UPDATE OleClient1.Action = OLE_CLOSE OleClient1.Action = OLE_DELETE End Sub  From the Run menu, choose Start. Run a utility such as Heap Walker to list the number of segments allocated to OLEClient.</li> Click the form to create and delete an OLE object from Microsoft Graph.</li></ol>

At this point, you'll see that the number of private segments allocated to OLEClient increases by 1.

Additional query words: buglist2.00 2.00 MemLeak

Keywords: kbbug KB97136

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© Microsoft Corporation. All rights reserved.