# ActionManager / PointerDragBehavior as a resource

**URL:** <https://forum.babylonjs.com/t/actionmanager-pointerdragbehavior-as-a-resource/23671>\
**Category:** Questions\
**Created:** [September 8, 2021, 2:26pm UTC](https://forum.babylonjs.com/t/actionmanager-pointerdragbehavior-as-a-resource/23671 "2021-09-08T14:26:07Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![zacherl](https://avatars.discourse-cdn.com/v4/letter/z/8dc957/32.png) [@zacherl](https://forum.babylonjs.com/u/zacherl)\
**Post date:** [September 8, 2021, 2:26pm UTC](https://forum.babylonjs.com/t/actionmanager-pointerdragbehavior-as-a-resource/23671/1 "2021-09-08T14:26:07Z")

</div>

Hello,

I’m currently wondering about action managers and pointer drag behaviors as resources (I hope I did not miss it in the documentation). We currently use several instances of action managers and pointer drag behaviors at the same time, e. g. when a new complex object is added, a new action manager and a new pointer drag behavior are created as well.

Since PointerDragBehavior creates a drag plane, I assume that it consumes resources. I checked the code - the drag plane is disposed when the scene is disposed. Do we pollute the memory if we create a lot of those behaviors? I did not find a dispose method on the behavior. Should I reuse them, can I apply the same behavior / action manager to multiple meshes at the same time? Or is there a method to dispose them when they are not used anymore?

Kind regards  
Zacherl

---

<div class="post-metadata">

**Author:** ![Deltakosh](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/deltakosh/32/26635_2.png) [@Deltakosh](https://forum.babylonjs.com/u/Deltakosh)\
**Post date:** [September 8, 2021, 3:05pm UTC](https://forum.babylonjs.com/t/actionmanager-pointerdragbehavior-as-a-resource/23671/2 "2021-09-08T15:05:28Z")

</div>

pinging @Cedric

---

<div class="post-metadata">

**Author:** ![sebavan](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/sebavan/32/57_2.png) [@sebavan](https://forum.babylonjs.com/u/sebavan)\
**Post date:** [September 8, 2021, 3:06pm UTC](https://forum.babylonjs.com/t/actionmanager-pointerdragbehavior-as-a-resource/23671/3 "2021-09-08T15:06:00Z")

</div>

ActionManager should be fine and not having one per mesh can be difficult.

Regarding the PointerDragBehavior, as long as you detach the unneeded ones they should not have much cost.

---

<div class="post-metadata">

**Author:** ![zacherl](https://avatars.discourse-cdn.com/v4/letter/z/8dc957/32.png) [@zacherl](https://forum.babylonjs.com/u/zacherl)\
**Post date:** [September 8, 2021, 3:24pm UTC](https://forum.babylonjs.com/t/actionmanager-pointerdragbehavior-as-a-resource/23671/4 "2021-09-08T15:24:04Z")

</div>

Thank you for your quick answer!

I checked the code in the pointer drag behavior - the dragPlane is not disposed during detach, only some observers are removed. So you think the remaining drag planes are not an issue?

> <https://github.com/BabylonJS/Babylon.js/blob/master/src/Behaviors/Meshes/pointerDragBehavior.ts>

---

<div class="post-metadata">

**Author:** ![sebavan](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/sebavan/32/57_2.png) [@sebavan](https://forum.babylonjs.com/u/sebavan)\
**Post date:** [September 8, 2021, 3:30pm UTC](https://forum.babylonjs.com/t/actionmanager-pointerdragbehavior-as-a-resource/23671/5 "2021-09-08T15:30:12Z")

</div>

so it will get disposed only when the main scene has been disposed. I do not think it consumes much memory but still I wonder if we could improve it, @Cedric ?

---

<div class="post-metadata">

**Author:** ![Cedric](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/cedric/32/2742_2.png) [@Cedric](https://forum.babylonjs.com/u/Cedric)\
**Post date:** [September 8, 2021, 3:44pm UTC](https://forum.babylonjs.com/t/actionmanager-pointerdragbehavior-as-a-resource/23671/6 "2021-09-08T15:44:25Z")

</div>

RAII, it should be disposed when detached. Let me do some tests …

---

<div class="post-metadata">

**Author:** ![Cedric](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/cedric/32/2742_2.png) [@Cedric](https://forum.babylonjs.com/u/Cedric)\
**Post date:** [September 8, 2021, 4:23pm UTC](https://forum.babylonjs.com/t/actionmanager-pointerdragbehavior-as-a-resource/23671/7 "2021-09-08T16:23:25Z")

</div>

I did a PR

> <https://github.com/BabylonJS/Babylon.js/pull/11029>
>
> follow up https://forum.babylonjs.com/t/actionmanager-pointerdragbehavior-as-a-r…esource/23671/6
> Tested with inspector on multiple meshes, multiple times.

---

<div class="post-metadata">

**Author:** ![zacherl](https://avatars.discourse-cdn.com/v4/letter/z/8dc957/32.png) [@zacherl](https://forum.babylonjs.com/u/zacherl)\
**Post date:** [September 8, 2021, 4:47pm UTC](https://forum.babylonjs.com/t/actionmanager-pointerdragbehavior-as-a-resource/23671/8 "2021-09-08T16:47:08Z")

</div>

Thank you all for your quick feedback!
