Container Control Not Closing in Tab Panel

Hey all,

Just discovered something while chasing down a memory leak, but I don’t know if this is a bug or expected behavior. It seems like a bug to me.

I have a window with a tab panel. The tab panel has two tabs. In each tab there’s a container control. When the window opens, the container controls are created and their open events fire. All good.

But, when I close the window, only the container control in the first tab fires its close event. The container control in the second tab NEVER fires its close event. Every object in that container control stays active. It doesn’t matter if that second tab is the active tab. The container control never fires its close.

To me, this is a bug. If a control fires its open event when created, it should fire the close event when it’s being closed. And if the window is not closing all containers on all tabs in a tab panel, that’s a problem…

Thoughts?

Do you have any other references to the container control, either from the outside in the window or from the inside in one of the controls? The container won’t close until its reference count is zero.

Are you embedding the container at design time, or in code?

If you add a destructor to the container does that fire?

If it does fire than there is a bug preventing the Close event from firing.

If it doesn’t then Tim in correct and there is a reference keeping the container from closing. If the extra reference is external to the window I would still expect the close event to fire. If the container has been kept as a property to a control on the container then that would be the cause. Using WeakRef will be a good solution to this sort of reference loop.

Thanks Ian and Tim,

The containers are both created at design time. They are nearly identical. There are no other references to the containers.

If I add the destructor methods as Ian says, the destructor methods for both containers fire, however, the Close method for the container in the second tab does not fire.

When closing the Window the Close Event of the container on the first tab fires. Then the destructor method in that container fires. Then the destructor method in the container on the first tab fires (but not the Close Event).

I’m curious… does the Open event fire on both containers?

The good news is that if the destructors are firing, they’re not leaking.

Yes. The open event fires on both.

Then it’s probably a bug.

No, but what was happening was I was executing code in the close event to shut down some socket operations and close some objects in use. Since that code was not running, all that stuff continued in the background eating memory at a large clip!

It’s what I am thinking. Time to make a “simple” app with a tab panel and a couple of containers…

1 Like

Agreed, certainly worth reporting.