Skip to content

Commit 28357f3

Browse files
ensure feature is destroyed to release memory
I think feature.Destroy() will cause g to be destroyed. The seg fault mentioned in the deleted comment happens because when defer g.Destroy() and defer feature.Destroy() are included, whichever happens second tries to destroy the geometry object that was already removed by the other call. When only g.Destroy() is called, g is destroyed, but the rest of the feature remains causing the memory leak.
1 parent 366b2a4 commit 28357f3

1 file changed

Lines changed: 2 additions & 3 deletions

File tree

resultswriters/spatialwriter.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -93,13 +93,13 @@ func (srw *spatialResultsWriter) Write(r consequences.Result) {
9393
//if header has been built, add the feature, and the attributes.
9494

9595
feature := layerDef.Create()
96-
//defer feature.Destroy()
96+
defer feature.Destroy() // Destroy feature. I believe this also destroys the geometry object g, defined below. If feature is not destroyed, memory is not released
9797
feature.SetFieldInteger(0, srw.index)
9898
//create a point geometry - not sure the best way to do that.
9999
x := 0.0
100100
y := 0.0
101101
g := gdal.Create(gdal.GeometryType(gdal.GT_Point))
102-
defer g.Destroy()
102+
// defer g.Destroy() // Don't Destroy g (I believe this is handled in feature.Destroy())
103103
for i, val := range r.Headers {
104104
if val == "x" {
105105
x = result[i].(float64)
@@ -182,7 +182,6 @@ func (srw *spatialResultsWriter) Write(r consequences.Result) {
182182
}
183183

184184
srw.index++ //incriment.
185-
//feature.Destroy() //testing an explicit call.//causes seg fault error, probably not calling causes a memory leak... oy vey.
186185
}
187186
func (srw *spatialResultsWriter) Close() {
188187
//not sure what this should do - Destroy should close resource connections.

0 commit comments

Comments
 (0)