Jump to content

[TOPIC: topicViewTemplate]
[GLOBAL: userSmallPhoto]
Photo

Memory question regarding function inside timer call
Started by d.mach Dec 03 2019 11:59 PM

- - - - -
2 replies to this topic
timer memory leak function
[TOPIC CONTROLS]
[/TOPIC CONTROLS]
[modOptionsDropdown]
[/modOptionsDropdown]
[reputationFilter]
[TOPIC: post.html]
#1

d.mach

[GLOBAL: userInfoPane.html]
d.mach
  • Contributor

  • 971 posts
  • Corona SDK

I wonder if it is okay to use a LOT of calls like this memory wise:

hpcounttimer=performWithDelay(1000,function() fc.countup_hp(value) end,1)

I wonder because there always is a function created inside the timer to get the (value) to the called function fc.countup_hp

 

Is this used memory for the function inside the timer getting freed when the timer hpcounttimer is canceled and set to nil?

 

Is it better to use this when the local function is always created when the timer is used, meaning whenever I click a button the function doitnow is created locally:

local doitnow=function()
       fc.countup_hp(value)
end

hpcounttimer=performWithDelay(1000,fc.countup_hp,1)


[TOPIC: post.html]
#2

sporkfin

[GLOBAL: userInfoPane.html]
sporkfin
  • Contributor

  • 810 posts
  • Corona SDK

I haven't noticed memory leaks using either of these approaches.  The biggest problem I have with a ton of timers is making sure they all get cancelled after completion.  I track all the timers and cancel them individually if they expire.



[TOPIC: post.html]
#3

carloscosta

[GLOBAL: userInfoPane.html]
carloscosta
  • Contributor

  • 688 posts
  • Corona SDK

i put my timers in a table. so it's pretty easy to cancel them all..just for loop the table...

same for the transitions.




[topic_controls]
[/topic_controls]

Also tagged with one or more of these keywords: timer, memory, leak, function