mirror of
https://github.com/atom/atom.git
synced 2026-01-22 21:38:10 -05:00
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:
@@ -8,6 +8,13 @@ describe "Project", ->
|
||||
beforeEach ->
|
||||
project.setPath(project.resolve('dir'))
|
||||
|
||||
describe "serialization", ->
|
||||
it "destroys unretained buffers and does not include them in the serialized state", ->
|
||||
project.bufferForPath('a')
|
||||
expect(project.getBuffers().length).toBe 1
|
||||
expect(deserialize(project.serialize()).getBuffers().length).toBe 0
|
||||
expect(project.getBuffers().length).toBe 0
|
||||
|
||||
describe "when an edit session is destroyed", ->
|
||||
it "removes edit session and calls destroy on buffer (if buffer is not referenced by other edit sessions)", ->
|
||||
editSession = project.open("a")
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
@@ -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: ->
|
||||
|
||||
Reference in New Issue
Block a user