Solved

VB6 ImageList control prevent Terminate Event

Posted on 2016-08-11
11
40 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
Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 
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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
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…

830 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