# How important it is to destroy a Timer

**URL:** <https://forums.unrealengine.com/t/how-important-it-is-to-destroy-a-timer/351034>\
**Category:** Debugging, Optimization, & Profiling\
**Tags:** Optimization, timers, unreal-engine, UE4, CPP, question\
**Created:** [March 19, 2016, 4:59am UTC](https://forums.unrealengine.com/t/how-important-it-is-to-destroy-a-timer/351034 "2016-03-19T04:59:10Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Narg](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/narg/32/870597_2.png) [@Narg](https://forums.unrealengine.com/u/Narg)\
**Post date:** [March 19, 2016, 4:59am UTC](https://forums.unrealengine.com/t/how-important-it-is-to-destroy-a-timer/351034/1 "2016-03-19T04:59:10Z")

</div>

Hello everyone

I’m working on an adventure game with lots of RPG Elements, and one of these elements are spells, I use A LOT of Timers in those Spells and since I’m terrible with optimizing C++ code, I was wondering exactly how important it is to actually destroy those timers and what is the best approach to do so. Most of them are used for Damage Over Time spells or Regeneration Spells and their Handlers and Delegates are defined within the .cpp function that calls them, not on the header.

PS: They don’t seem to have any impact on performance whatsoever this far, even when casting 10, 20 spells, I’m just asking this so they don’t become an issue in the long run.

---

<div class="post-metadata">

**Author:** ![BrUnO\_XaVIeR](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/bruno_xavier/32/1110230_2.png) [@BrUnO\_XaVIeR](https://forums.unrealengine.com/u/BrUnO_XaVIeR)\
**Post date:** [March 29, 2016, 11:44am UTC](https://forums.unrealengine.com/t/how-important-it-is-to-destroy-a-timer/351034/2 "2016-03-29T11:44:10Z")

</div>

When the owning object is destroyed, GC takes care of the timers for you.

---

<div class="post-metadata">

**Author:** ![Narg](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/narg/32/870597_2.png) [@Narg](https://forums.unrealengine.com/u/Narg)\
**Post date:** [March 31, 2016, 12:01am UTC](https://forums.unrealengine.com/t/how-important-it-is-to-destroy-a-timer/351034/3 "2016-03-31T00:01:25Z")

</div>

Ty for replying, but what about persistent objects? Example, if I have a spell that heals the actor overtime, but the whole local timer is created and handled on the actor doing the healing, so he can stack heals, in that case, do I need to destroy the timer once that stack of the healing ends? Sorry if this question is too dumb btw.

---

<div class="post-metadata">

**Author:** ![BrUnO\_XaVIeR](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/bruno_xavier/32/1110230_2.png) [@BrUnO\_XaVIeR](https://forums.unrealengine.com/u/BrUnO_XaVIeR)\
**Post date:** [April 3, 2016, 2:25am UTC](https://forums.unrealengine.com/t/how-important-it-is-to-destroy-a-timer/351034/4 "2016-04-03T02:25:00Z")

</div>

Unless you’re making something very specific, when owner actor is destroyed its Uobjects should be destroyed too. If you’re not sure, call BeginDestroy() on the Uobject within the overriden Actor’s destructor function.  
You should not create a timer object everytime you want to use a skill, the timer object is destroyed with the owning actor so there’s no reason to delete and rebuild the timer object more than once.

---

<div class="post-metadata">

**Author:** ![Narg](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/narg/32/870597_2.png) [@Narg](https://forums.unrealengine.com/u/Narg)\
**Post date:** [April 7, 2016, 4:23pm UTC](https://forums.unrealengine.com/t/how-important-it-is-to-destroy-a-timer/351034/5 "2016-04-07T16:23:00Z")

</div>

Oh, I think I got it ! Thank you very much!
