dagda1
dagda1

Reputation: 28770

ember.js containerview concerns

I am using a containerview where I dynamically add and remove contextual forms using the currentview property, a bit like this:

showSomeForm: ->
  form = @get('theContainerView')

  if form.get('currentView')
    form.set('currentView', null)

  contextualForm = App.Form.create
                     controller: App.Controller.create()

showSomeOtherForm: ->
  form = @get('theContainerView')

My worry is about memory leaks with creating the controller each time and if this is the best way of doing things.

Once the user has completed the contextual form, I also set currentView to null in order to hide it.

Is there a better way of doing this, I am currently on ember v1.0.0-pre.2-54.

Upvotes: 0

Views: 219

Answers (1)

Yehuda Katz
Yehuda Katz

Reputation: 28703

You shouldn't have to worry about memory leaks here.

You are assigning the controller to a view inserted into a currentView, and not otherwise holding a reference to it. When the view is torn down (when the container view's currentView gets set to null or something else), Ember will destroy it. This will release any remaining references to it, which will let the GC collect it, and the referenced controller along with it.

If this is not true for some reason, it is probably an Ember bug.

Upvotes: 1

Related Questions