Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Revised Tooltip & ContextMenuItem for GC #1002

Draft
wants to merge 2 commits into
base: dev
Choose a base branch
from

Conversation

ynzenu
Copy link

@ynzenu ynzenu commented Feb 24, 2025

This PR aims to solve the issues described in: #941:

Tooltip & Menu

  • Inherit from a new base class ReferencedCountedContainer that will track how many times the object is used by controls.
  • Are disposed when they not used by any controls (done by setting the property to null during control disposal).
  • The Tooltip is also removed from the static _allTooltips property when the Tooltip is disposed to avoid any left-over references.

Example:

var tooltip = new Tooltip()
var imageControl = new Image();
var labelControl = new Label();

imageControl.Tooltip = tooltip; //_referenceCount = 1
labelControl.Tooltip = tooltip; //_referenceCount = 2

imageControl.Dispose() //Tooltip is not disposed (_referenceCount = 1)
labelControl.Dispose() //Tooltip is disposed (_referenceCount = 0)

Finalizer

A finalizer has been added to the Control class to ensure that Dispose is called when objects are collected by the GC. However, this still does not guarantee that it's disposed when the program is terminated. This is only a problem when classes derived from Control use unmanaged resources that are released by the dispose method.

Potential problems

The DisposeControl method is not guaranteed to be called in every scenario. An example of this is when the program is terminated, because the GC may not have called the finalizer on the control at that point. This means that any unmanaged resources could linger while they should have been released by the DisposeControl method.

Is this a breaking change?

Breaking changes require additional review prior to merging. If you answer yes, please explain what breaking changes have been made.

No

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant