Skip to content

fix: Memory leaks in label components #2

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

Closed

Conversation

devin-ai-integration[bot]
Copy link

@devin-ai-integration devin-ai-integration bot commented Nov 15, 2024

Memory Leak Fixes in Label Components

This PR addresses memory leaks identified in the Label Studio Frontend components, specifically focusing on proper cleanup of Konva canvas elements and event listeners.

Changes Made

LabelOnBbox Component

  • Added cleanup for textEl using useEffect
  • Memoized event handlers to prevent unnecessary re-renders
  • Fixed dependency arrays in useMemo and useCallback hooks
  • Added proper cleanup for event listeners

LabelOnPolygon Component

  • Added cleanup for Rect elements using useEffect
  • Implemented proper canvas element disposal using refs

LabelOnMask Component

  • Added cleanup for Group and Rect elements
  • Implemented proper canvas element disposal
  • Used refs to track and cleanup Konva elements

LabelOnKP Component

  • Added cleanup for Group element
  • Standardized component interface to use consistent prop names

LabelOnVideoBbox Component

  • Added cleanup for Group and Rect elements
  • Standardized component interface
  • Implemented proper canvas element disposal

Testing

  • Tested locally with large datasets to verify memory usage
  • Verified proper cleanup of canvas elements using Chrome DevTools Memory Profiler
  • Confirmed event listeners are properly disposed of on component unmount

Impact

These changes should significantly reduce memory leaks by ensuring proper cleanup of:

  • Canvas elements
  • Event listeners
  • Text elements
  • Group elements

Link to Devin run: https://preview.devin.ai/devin/27000cb55746455d8d54a7d4659cb197

If you have any feedback, you can leave comments in the PR and I'll address them in the app!

- Add cleanup for textEl using useEffect
- Memoize event handlers to prevent unnecessary re-renders
- Fix dependency arrays in useMemo and useCallback hooks
- Optimize canvas element disposal
- Add proper cleanup for event listeners

Part of memory leak fixes in label components.
- Add cleanup for Rect elements using useEffect in LabelOnPolygon
- Add cleanup for Group and Rect elements in LabelOnMask
- Implement proper canvas element disposal
- Use refs to track and cleanup Konva elements

Part of memory leak fixes in label components.
- Add cleanup for Group element in LabelOnKP
- Add cleanup for Group and Rect elements in LabelOnVideoBbox
- Standardize component interfaces to use consistent prop names
- Implement proper canvas element disposal
- Use refs to track and cleanup Konva elements

Part of memory leak fixes in label components.
@devin-ai-integration devin-ai-integration bot added the enhancement New feature or request label Nov 15, 2024
@devin-ai-integration devin-ai-integration bot changed the title PAR-0: Fix memory leaks in label components fix: Memory leaks in label components Nov 15, 2024
Copy link
Author

Closing due to inactivity.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request fix
Projects
None yet
Development

Successfully merging this pull request may close these issues.

0 participants