Solved

VB6 ImageList control prevent Terminate Event

Posted on 2016-08-11
11
38 Views
Last Modified: 2016-09-23
I am helping out supporting a VB6 project that has a couple of UserControls. I have been tracking down a memory leak issue.

I've narrowed it down to one of the controls that doesn't unload properly even though it doesn't seem to be referenced elsewhere.

I've replicated the problem in a demo app, and attached it as a zip file. You'll need to rename the .txt files to .ctl before opening the project though. EE won't accept .ctl files yet.

Im summary, with the check box unchecked, the Terminate Event fires when Form2 closes (as I need it to), but when it is checked, it doesn't fire until the app closes down (form1 closes). The behavior seems to be the same both compiled and in the IDE.

I'm hoping you can help.
image-list-dispose-problem.zip
0
Comment
Question by:JedNebula
  • 5
  • 4
11 Comments
 
LVL 1

Author Comment

by:JedNebula
ID: 41752439
I have since tried changing the ImageList control for a CommandButton and the same thing happens.
0
 
LVL 46

Expert Comment

by:Martin Liss
ID: 41752902
I don't know if you consider this an acceptable solution but this resolves the problem.

Private Sub Command1_Click()
Dim x As New Form2

    'x.MyProductMenu.bIgnoreSet = (chkInitImageList.Value = vbUnchecked)
    x.MyProductMenu.bIgnoreSet = True
    
    x.Show
    
End Sub

Open in new window

0
 
LVL 1

Author Comment

by:JedNebula
ID: 41753460
Thank you Martin, but I think that just bypasses the test.

I need to pass the object reference to the child control and still have the parent control terminate event fire when it should.
0
ScreenConnect 6.0 Free Trial

At ScreenConnect, partner feedback doesn't fall on deaf ears. We collected partner suggestions off of their virtual wish list and transformed them into one game-changing release: ScreenConnect 6.0. Explore all of the extras and enhancements for yourself!

 
LVL 46

Expert Comment

by:Martin Liss
ID: 41754522
I added some Debug.Print statements to this project. I don't think I did anything else but the app shows the same results with or without the checkbox being checked.
28962832.zip
0
 
LVL 1

Author Comment

by:JedNebula
ID: 41762304
Hi Martin,

You code supresses the ImageList being passed to the button so it cannot be used.

I need the control to be passed. I just put the option not to pass it, to demonstrate that this seems to be causing the problem with the Terminate event.

I've attached the project again with example usage of the control. (the
28962832.zip
0
 
LVL 46

Expert Comment

by:Martin Liss
ID: 41762773
I've never used it but from what I've read, the Ambient.UserMode property "specifies if the environment is in design mode or end user mode". Why do you care about that and have you tested the app for memory leaks in both the IDE and as an exe?
0
 
LVL 1

Author Comment

by:JedNebula
ID: 41762824
Hi Martin,

Yes as I put in my original question, the behaviour seems the same when compiled as an exe and in the IDE.

You're right about the UserMode property's use. Tbh you could probably strip that part out of the code of you want. I just do it out of habbit because it stops the events firing when you're designing forms and only fires them when the app is running.
0
 
LVL 46

Expert Comment

by:Martin Liss
ID: 41763223
In the code for MyProductMenu change

Private Sub UserControl_Terminate()

to

Public Sub UserControl_Terminate()

and in Form2 Form_Unload add

MyProductMenu.UserControl_Terminate
0
 
LVL 1

Accepted Solution

by:
JedNebula earned 0 total points (awarded by participants)
ID: 41764887
Hi Martin,

Thanks for the suggestion. I have since got round the problem my invoking a sub to clear the control reference from the child controls, then the controls seems to unload fine.

With your suggestion though, you'll notice that although the Terminate event fires, the controls are still in memory and do not unload until the app closes.

Sorry that I wasn't clear initially... I have a workaround for the issue in my actual project. I was just posting here because  I was curious as to the cause... and if anyone else had experience the same thing or could point me to a link explaining that behavior at all - so I could avoid it in the future.
0

Featured Post

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

831 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question