This is a read-only archive of the Framer Community on Facebook.

What is Framer? Join the Community
Return to index
Fran Pérez
Posted Sep 04 - Read on Facebook

Who can explain me this?

11 Comments

Koen Bok

Destroy means remove from screen forever, you can still keep a reference to it in js.

Fran Pérez

That's what I thought, thanks Koen :)

Jordan Robert Dobson

So once you destroy you also need to clear your var. that confused me too initially.

Fran Pérez

Out of curiosity, how do you do that? I thought variables created using var (coffee way) can't be deleted/cleared.

Jordan Robert Dobson

layer = null

I guess I assume eventually it will get garbage collected.

Fran Pérez

Oh yeah, I knew that one :)

Alex Conner

This would have helped me out so much like a year ago when Framer was brand new

Alex Conner

This would have helped me out so much like a year ago when Framer was brand new

Koen Bok

This is pretty nice to read if you'd like to become a pro: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Memory_Management

Koen Bok

TLDR; JavaScript automatically claims memory when you create any object, and returns it whenever you're "done" with it, meaning that you have no reference to it anymore.

This is smartly called "garbage collection", because it doesn't do it right away but once every x time. The upside is convenience for programmers like us, the downside that these garbage collection events are unpredictable and can cause animations to drop frames.

Balraj Chana

I had the garbage collection problem when I built SpaceInFramers. The ball would still collide with the target even after the object was destroyed. I worked around this by pushing the layers inside an array and then -> splice -> destroy to ensure the next ball couldn't reference the target that was destroyed after collision.

Read the entire post on Facebook