Skip to content

[drag-drop] Memory Leak: DragRef _resizeSubscription - failing to unsubscribe #17255

@Achilles1515

Description

@Achilles1515

After fighting a memory leak in my app (involving dynamically generating/removing CDK drag-drop items - and those removed items still lingering around in memory) for longer than I'd like to admit, I finally figured out the memory leak only occurs when the cdkDrag items contain a cdkDragBoundary property.

This bug was introduced in release 8.2.0 (#16874) when _resizeSubscription was added.

image

All the subscriptions in the screenshot above are being unsubscribed in the dragRef._removeSubscriptions() method except for the _resizeSubscription.

image

As a result, the _resizeSubscription is not closed within the dragRef.dispose() method.

image

Simply adding this._resizeSubscription.unsubscribe(); to the dragRef._removeSubscriptions() method appears to fix the problem.

I just double checked and the memory leak I am experiencing does not occur on CDK v8.1.4.

Environment

  • Angular:
  • CDK/Material: 8.2.0+
  • Browser(s):
  • Operating System (e.g. Windows, macOS, Ubuntu):

Metadata

Metadata

Assignees

Labels

P2The issue is important to a large percentage of users, with a workaround

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions