Solved

VB6 ImageList control prevent Terminate Event

Posted on 2016-08-11
11
50 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 47

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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 47

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 47

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 47

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

Instantly Create Instructional Tutorials

Contextual Guidance at the moment of need helps your employees adopt to new software or processes instantly. Boost knowledge retention and employee engagement step-by-step with one easy solution.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
using Access 8 96
Add and format columns in vb6 7 85
VBA - Excel, Hide/unhide range of rows on sheet with listbox selection 9 136
VB script to continue despite error 2 78
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…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…

710 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