470,587 Members | 2,333 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 470,587 developers. It's quick & easy.

Dynamic ActiveX controls memory leak (URGENT)

My vb6 application has a nasty memory leak that I can't trace for the life of me. I have an ActiveX object that I've created called an Operation. The control has the following components :

Picturebox (x3)
Label (x4)
TextBox (x2)
ListBox
ScrollBar
CommonDialog
ImageList
Timer

In code, the control has the following member Objects:

m_AllVersions As Collection
m_ModulePaths As Collection
m_Parameters As Collection
m_Measurements As Collection

In my UserControl_Initialize routine, I have a bunch of lines that set flags, configure the various texboxes and things, and I set each Collection to a New one. Nothing very fancy. I put a Debug.Print statement in to let me know that the Object has been created.

verbatem, here is my terminate method:
Expand|Select|Wrap|Line Numbers
  1. Private Sub UserControl_Terminate()
  2.  
  3.     'remove references to objects
  4.     Set m_AllVersions = Nothing
  5.     Set m_ModulePaths = Nothing
  6.     Set m_Parameters = Nothing
  7.     Set m_Measurements = Nothing
  8.  
  9.     Debug.Print vbTab & "OPERATION DESTROYED!!"
  10.  
  11. End Sub
  12.  
These Operation Objects are created dynamically when needed, so I have a method to create and destroy them from within another ActiveX control called a Module

Expand|Select|Wrap|Line Numbers
  1. Friend Function CreateOperation() As Operation
  2.  
  3.     Dim Opn As Operation
  4.     Static ControlIndex As Integer
  5.  
  6.     Set Opn = Controls.Add("Project1.Operation", "Module" & m_ControlIndex _
  7.         & "Operation" & ControlIndex)
  8.  
  9.     Opn.Move 0, 0, Extender.Width, Extender.Height
  10.     Opn.ControlIndex = ControlIndex
  11.  
  12.     ControlIndex = ControlIndex + 1
  13.     Set CreateOperation = Opn
  14.  
  15. End Function
  16.  
  17. Friend Sub DestroyOperation(ByRef Opn As Operation)
  18.  
  19.     Dim Index As Integer
  20.  
  21.     'explicitly remove reference to Operation in
  22.     '   all Parameter objects
  23.     For Index = 0 To Opn.ParamCount - 1
  24.  
  25.         Opn.RemoveParameter 0
  26.  
  27.     Next
  28.  
  29.     'explicitly remove reference to Operation in
  30.     '   all Measurement Objects
  31.     For Index = 0 To Opn.MeasCount - 1
  32.  
  33.         Opn.RemoveMeasurement 0
  34.  
  35.     Next
  36.  
  37.     'Remove Operation object from Controls Collection
  38.     Controls.Remove "Module" & m_ControlIndex & "Operation" & Opn.ControlIndex
  39.     Set Opn = Nothing
  40.  
  41. End Sub
  42.  
  43.  
Pay no attention to the RemoveParameter and RemoveMeasurement lines, Opn.ParamCount and Opn.MeasCount are 0 for testing.

Okay, so to test that everything is working, I just create and destroy the Operation Objects in a loop:

Expand|Select|Wrap|Line Numbers
  1. Dim i As Integer
  2. Dim Opn As Operation
  3.  
  4. For i = 1 To 1000
  5.  
  6.      Debug.Print "CREATING OPERATION " & i
  7.      Set Opn = Modl.CreateOperation
  8.      Modl.DestroyOperation Opn
  9.      Set Opn = Nothing
  10.  
  11. Next
  12.  
When I execute this, I get messages in the Immediate window letting me know that the objects are being created and destroyed, but after about 342 times through the loop, I get an Error - 7 Out of Memory.

Any ideas? Is there something unique about ActiveX objects that prevents them from being returned to memory properly?
Oct 9 '06 #1
1 2674
I don't know if this will help trace the problem, but it looks like something is going on inside the VB6 Developer environment.

As I said in the previous post, when I simply create and destroy 1000 of the Operation Objects, the debugger crashes and gives me the Out of Memory error.

However, when I open a project that has the ActiveX project as a reference, it is able to create all 1000 Operation Objects and destroy them without complaining.

Is there something I'm missing in the developer environment?
Oct 9 '06 #2

Post your reply

Sign in to post your reply or Sign up for a free account.

By using this site, you agree to our Privacy Policy and Terms of Use.