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.
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’scurrentViewgets set tonullor something else), Ember willdestroyit. 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.