All ace editors must die. I found that certain editor modes will leave a mess in memory, so when editors are destroyed, I also set their modes to '' which seems to take care of most of the issue. They still leave memory behind just a little bit, though.

This commit is contained in:
Scott Erickson 2014-08-29 18:02:29 -07:00
parent 3f6c9c4f02
commit 21e0889a86
17 changed files with 69 additions and 7 deletions

View file

@ -234,3 +234,7 @@ module.exports = class AccountSettingsView extends RootView
$(@).data 'saved-value', $(@).val()
$('#settings-panes input:checkbox').each ->
$(@).data 'saved-value', JSON.stringify $(@)[0].checked
destroy: ->
@pictureTreema?.destroy()
super()

File diff suppressed because one or more lines are too long

View file

@ -26,13 +26,16 @@ module.exports = class LevelSessionCodeView extends CocoView
afterRender: ->
super()
editors = []
@$el.find('.code').each (index, codeEl) ->
height = parseInt($(codeEl).data('height'))
$(codeEl).height(height)
editor = ace.edit codeEl
editor.setReadOnly true
editors.push editor
aceSession = editor.getSession()
aceSession.setMode 'ace/mode/javascript'
@editors = editors
organizeCode: ->
team = @session.get('team') or 'humans'
@ -47,4 +50,8 @@ module.exports = class LevelSessionCodeView extends CocoView
name: spell
height: height
}
filteredSpells
filteredSpells
destroy: ->
for editor in @editors
@editors

View file

@ -92,6 +92,10 @@ module.exports = class ThangComponentConfigView extends CocoView
@trigger 'changed', { component: @component, config: @config }
data: -> @editThangTreema.data
destroy: ->
@editThangTreema?.destroy()
super()
class ComponentConfigNode extends TreemaObjectNode
nodeDescription: 'Component Property'

View file

@ -342,7 +342,10 @@ module.exports = class ThangComponentsEditView extends CocoView
@loadComponents(sparseComponents)
@components = @components.concat(sparseComponents)
@onComponentsChanged()
destroy: ->
@componentsTreema?.destroy()
super()
class ThangComponentsObjectNode extends TreemaObjectNode
addNewChild: -> @addNewChildForKey('') # HACK to get the object adding to act more like adding to an array

View file

@ -81,6 +81,10 @@ module.exports = class ComponentsTabView extends CocoView
onLevelComponentEditingEnded: (e) ->
@removeSubView @levelComponentEditView
@levelComponentEditView = null
destroy: ->
@componentsTreema?.destroy()
super()
class LevelComponentNode extends TreemaObjectNode
valueClass: 'treema-level-component'

View file

@ -84,7 +84,7 @@ module.exports = class LevelComponentEditView extends CocoView
@levelComponent.set 'configSchema', @configSchemaTreema.data
buildCodeEditor: ->
@editor?.destroy()
@destroyAceEditor(@editor)
editorEl = $('<div></div>').text(@levelComponent.get('code')).addClass('inner-editor')
@$el.find('#component-code-editor').empty().append(editorEl)
@editor = ace.edit(editorEl[0])
@ -120,5 +120,7 @@ module.exports = class LevelComponentEditView extends CocoView
button.find('> span').toggleClass('secret')
destroy: ->
@editor?.destroy()
@destroyAceEditor(@editor)
@componentSettingsTreema?.destroy()
@configSchemaTreema?.destroy()
super()

View file

@ -83,6 +83,7 @@ module.exports = class ScriptsTabView extends CocoView
newPath = selected.getPath()
return if newPath is @selectedScriptPath
@scriptTreema?.destroy()
@scriptTreema = @$el.find('#script-treema').treema treemaOptions
@scriptTreema.build()
@scriptTreema.childrenTreemas?.noteChain?.open()
@ -114,7 +115,11 @@ module.exports = class ScriptsTabView extends CocoView
onThangsEdited: (e) ->
# Update in-place so existing Treema nodes refer to the same array.
@thangIDs?.splice(0, @thangIDs.length, @getThangIDs()...)
destroy: ->
@scriptTreema?.destroy()
@scriptTreemas?.destroy()
super()
class ScriptsNode extends TreemaArrayNode
nodeDescription: 'Script'

View file

@ -60,6 +60,10 @@ module.exports = class SettingsTabView extends CocoView
onThangsEdited: (e) ->
# Update in-place so existing Treema nodes refer to the same array.
@thangIDs?.splice(0, @thangIDs.length, @getThangIDs()...)
destroy: ->
@settingsTreema?.destroy()
super()
class SettingsNode extends TreemaObjectNode

View file

@ -78,7 +78,7 @@ module.exports = class LevelSystemEditView extends CocoView
@levelSystem.set 'configSchema', @configSchemaTreema.data
buildCodeEditor: ->
@editor?.destroy()
@destroyAceEditor(@editor)
editorEl = $('<div></div>').text(@levelSystem.get('code')).addClass('inner-editor')
@$el.find('#system-code-editor').empty().append(editorEl)
@editor = ace.edit(editorEl[0])
@ -114,5 +114,7 @@ module.exports = class LevelSystemEditView extends CocoView
button.find('> span').toggleClass('secret')
destroy: ->
@editor?.destroy()
@destroyAceEditor(@editor)
@systemSettingsTreema?.destroy()
@configSchemaTreema?.destroy()
super()

View file

@ -121,6 +121,10 @@ module.exports = class SystemsTabView extends CocoView
{original: '528114e60268d018e300001a', majorVersion: 0} # UI
{original: '528114040268d018e3000011', majorVersion: 0} # Physics
]
destroy: ->
@systemsTreema?.destroy()
super()
class LevelSystemNode extends TreemaObjectNode
valueClass: 'treema-level-system'

View file

@ -183,6 +183,7 @@ module.exports = class ThangsTabView extends CocoView
@selectAddThangType null
@surface.destroy()
$(document).unbind 'contextmenu', @preventDefaultContextMenu
@thangsTreema?.destroy()
super()
onViewSwitched: (e) ->

View file

@ -21,6 +21,7 @@ module.exports = class ThangTypeColorsTabView extends CocoView
@interval = setInterval f, 1000
destroy: ->
@colorGroups?.destroy()
clearInterval @interval
super()

View file

@ -65,6 +65,13 @@ module.exports = class CocoView extends Backbone.View
@destroy = doNothing
$.noty.closeAll()
destroyAceEditor: (editor) ->
# convenience method to make sure the ace editor is as destroyed as can be
return unless editor
session = editor.getSession()
session.setMode ''
editor.destroy()
afterInsert: ->
willDisappear: ->

View file

@ -69,3 +69,7 @@ module.exports = class ModelModal extends ModalView
res.success (model, response, options) =>
return if @destroyed
@hide()
destroy: ->
@modelTreemas[model].destroy() for model of @modelTreemas
super()

View file

@ -80,6 +80,7 @@ module.exports = class SpellView extends CocoView
createACE: ->
# Test themes and settings here: http://ace.ajax.org/build/kitchen-sink.html
aceConfig = me.get('aceConfig') ? {}
@destroyAceEditor(@ace)
@ace = ace.edit @$el.find('.ace')[0]
@aceSession = @ace.getSession()
@aceDoc = @aceSession.getDocument()
@ -710,5 +711,6 @@ module.exports = class SpellView extends CocoView
@ace?.destroy()
@aceDoc?.off 'change', @onCodeChangeMetaHandler
@aceSession?.selection.off 'changeCursor', @onCursorActivity
@destroyAceEditor(@ace)
@debugView?.destroy()
super()

View file

@ -586,3 +586,7 @@ module.exports = class JobProfileView extends UserView
session = _.find @sessions.models, (session) -> session.id is sessionID
modal = new JobProfileCodeModal({session:session})
@openModalView modal
destroy: ->
@remarkTreema?.destroy()
super()