Destroy unretained buffers when serializing project

Previously buffers could linger indefinitely if an error occurred
during startup between the deserialization of the project and the
original retaining edit session.
This commit is contained in:
Kevin Sawicki & Nathan Sobo
2013-08-28 18:37:40 -07:00
parent 40b6183937
commit 2bd4386090
3 changed files with 15 additions and 1 deletions

View File

@@ -91,9 +91,14 @@ class Project
serialize: ->
state = @state.clone()
state.set('path', @getPath())
@destroyUnretainedBuffers()
state.set('buffers', buffer.serialize() for buffer in @getBuffers())
state
# Private:
destroyUnretainedBuffers: ->
buffer.destroy() for buffer in @getBuffers() when not buffer.isRetained()
# Public: ?
getState: -> @state

View File

@@ -81,13 +81,15 @@ class TextBuffer
@destroyed = true
@project?.removeBuffer(this)
isRetained: -> @refcount > 0
retain: ->
@refcount++
this
release: ->
@refcount--
@destroy() if @refcount <= 0
@destroy() unless @isRetained()
this
serialize: ->