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

AG-13363 Long-Tap iOS Safari #3442

Open
wants to merge 8 commits into
base: latest
Choose a base branch
from
Open

AG-13363 Long-Tap iOS Safari #3442

wants to merge 8 commits into from

Conversation

olegat
Copy link
Contributor

@olegat olegat commented Jan 30, 2025

@olegat olegat added the blocked label Jan 30, 2025
@olegat olegat force-pushed the AG-13363/longtap_iOS branch from d7afc0f to a02e98e Compare January 30, 2025 12:09
@olegat olegat removed the blocked label Jan 30, 2025
@olegat olegat marked this pull request as ready for review January 30, 2025 12:41
@olegat olegat requested a review from alantreadway as a code owner January 30, 2025 12:41
}
};
const touchend = (endEvent: TouchEvent) => {
longTapInterrupted = true;
Copy link
Member

@alantreadway alantreadway Jan 30, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the cases where longTapInterrupted is set to true, could you cancel the setTimeout() via clearTimeout() so that we don't have dangling JS variable contexts hanging around?

It would also be good if we could clear these up on chart.destroy() too, otherwise the callback could happen after chart destruction, with inevitable errors - also references in the callback context can prevent garbage collection?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the cases where longTapInterrupted is set to true, could you cancel the setTimeout() via clearTimeout() so that we don't have dangling JS variable contexts hanging around?

Can you clarify how we would end up with a dangling reference? I don't mind using clearTimeout(), but I cannot see how that improves memory safety. Without a clearTimeout(), the setTimeout() will eventually call then remove the function, which would in turn make its variable context eligible for garbage collection.

It would also be good if we could clear these up on chart.destroy() too, otherwise the callback could happen after chart destruction, with inevitable errors

The callbacks will not cause errors because we always remove the listeners on chart.destroy() (see WidgetListenerInternal.destroy()). So these callbacks will, at worst, loop through an undefined or empty array of listeners.

Calling chart.destroy() whilst a finger is being dragged on that chart can indeed delay garbage collection until after the finger is lifted. Removing the listeners on chart.destroy() isn't necessary, but it would stop this delay. However, the challenge is that these are global callbacks shared amongst all chart instances, we must be cautious to ensure that destroying one chart doesn't interrupt another chart that's currently being dragged.

We could perhaps refactor the startMouseDrag and startOneFingerTouch to be temporary member objects of WidgetListenerInternal to manage the memory better. But the way I see it there's very little gain in doing that: there's only one mouse & touch device in the window and therefore there's only ever one drag motion in progress. So we can safely manage the memory regardless of whether or not the chart gets destroyed.

also references in the callback context can prevent garbage collection?

Are you referring to that.globalTouchDragCallbacks? If yes, that variable is used correctly AFAIK. It sets to undefined either in the touchend handler (called on 'touchstart', 'touchend' or 'touchcancel') or in the WidgetListenerInternal.destroy() method (called by chart.destroy()).

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.

2 participants