When does Reactive Var gets destroyed?


#1

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?


#2

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


#3

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)