When does Reactive Var gets destroyed?

Hi!

Does anyone know when does a reactive Var gets destroyed? Do i need to manually destroy the reactive Var when the template is destroyed?

It’s just a variable so it will be destroyed when it goes out of scope.

If you want to make sure that reactive vars get destroyed you should bind them to the template instance in an onCreated or onRendered call

Template.test.onCreated(function(){
 this.testVar = new ReactiveVar();
});

This ensures that it will get deleted as soon as the instance of the template is deleted (and makes it possible to have multiple instances of 1 template, each with their own state)

1 Like