Microsoft KB Archive/257523

= BUG: Resource Leak Occurs When You Display WMF Files in a PictureBox =

Article ID: 257523

Article Last Modified on 10/15/2002

-

APPLIES TO


 * Microsoft Visual Basic 5.0 Professional Edition
 * Microsoft Visual Basic 6.0 Professional Edition
 * Microsoft Visual Basic 5.0 Enterprise Edition
 * Microsoft Visual Basic 6.0 Enterprise Edition

-



This article was previously published under Q257523



SYMPTOMS
System and Graphical Device Interface (GDI) resources are not freed when you use a PictureBox control in Visual Basic to view multiple Windows MetaFile (WMF) images. Other image formats, such as BMP, JPG, and GIF, do not experience any resource leaks.



CAUSE
The resource leak is actually caused by a problem in the operating system. The operating system fails to destroy brushes that it creates to "play" a metafile image. Therefore, any application that uses the same operating system functionality to draw metafiles will experience the same loss in resources.



RESOLUTION
Currently, there is no known fix for this problem. One potential workaround, however, is to avoid the WMF file format and instead use another picture format, such as BMP, JPG, or GIF.



STATUS
Microsoft has confirmed that this is a bug in the Microsoft products that are listed at the beginning of this article.



MORE INFORMATION
This resource leak only affects WMF files displayed on a Windows 95 or 98 operating system. Files in other formats, such as BMP, JPG, and GIF, are not affected. In addition, resources are only leaked once for each WMF file. For example, if you load one WMF file into a PictureBox 10 times resources leak only once, but if you load 10 unique WMF files one time each this results in a loss of 10 times as many resources.

Upon termination of the application, all leaked resources are released and available to the system.

Steps to Reproduce Behavior
 Create a new standard EXE project. Form1 is created by default. Add a PictureBox control to Form1. Add a command button to Form1. Add a reference to "Microsoft Scripting Runtime".  Paste the following code into the Form1 code window: Private Sub Command1_Click Dim fso As FileSystemObject Dim fld As Folder Dim fl As File

Set fso = New FileSystemObject Set fld = fso.GetFolder(App.Path & "\wmf")

For Each fl In fld.Files Picture1.Picture = LoadPicture(fl) Next fl

Set fld = Nothing Set fso = Nothing End Sub </li> Save the project.</li> In the project directory, create a subfolder called "WMF".</li> Copy some WMF files (preferably at least 200) to the folder that you just created.</li> Start the Resource Meter (or any tool that can measure free resources).</li> Run the sample program.</li> Click the command button. As the images are displayed, you can see that the resources available begin to dwindle.</li> When all images have been processed, close the application. You should see the resources returned to the system.</li></ol>

Keywords: kbbug kbbrush kbpending KB257523

-

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

© Microsoft Corporation. All rights reserved.