Code

Opened 5 years ago

Closed 5 years ago

Last modified 3 years ago

#12101 closed (fixed)

django.contrib.gis.gdal.OGRGeometry leaking memory

Reported by: nino@… Owned by: jbronn
Component: GIS Version: 1.1
Severity: Keywords: GDAL, memory, leak
Cc: techlog@… Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: UI/UX:

Description

gdal.OGRGeometry from WKB and WKT leaks memory like crazy (using GDAL 1.6.0, on debian). Reference counts do not appear to go up, but memory climbs rapidly.

From WKB:

from django.contrib.gis.geos import Point
from django.contrib.gis import gdal

geom = Point(1,1)
geom.srid = 4326
for i in xrange(1000000):
   g = gdal.OGRGeometry(geom.wkb, geom.srid)
   del g

From WKT:

from django.contrib.gis.geos import Point
from django.contrib.gis import gdal

geom = Point(1,1)
geom.srid = 4326
for i in xrange(1000000):
   g = gdal.OGRGeometry(geom.wkt, geom.srid)
   del g

Attachments (1)

gdal_leak_fix.diff (633 bytes) - added by jbronn 5 years ago.
Fixes memory leak when assigning SpatialReference to OGRGeometry

Download all attachments as: .zip

Change History (5)

comment:1 Changed 5 years ago by jbronn

  • milestone set to 1.2
  • Needs documentation unset
  • Needs tests unset
  • Owner changed from nobody to jbronn
  • Patch needs improvement unset
  • Status changed from new to assigned

I've confirmed this is as a bug, the leak is real. I think it's within the SpatialReference code because there's no balloon in memory usage when I change to this:

for i in xrange(1000000):
   g = gdal.OGRGeometry(geom.wkt)
   del g

Changed 5 years ago by jbronn

Fixes memory leak when assigning SpatialReference to OGRGeometry

comment:2 Changed 5 years ago by jbronn

I've come up with a patch that works, and all tests pass with it. However I can't fully explain yet why it works over the previous version, other than that somehow the cloned SpatialReference object references (within OGR, not Python) were not being released. As soon as I can explain why those references were not being released, I'll commit the patch.

comment:3 Changed 5 years ago by jbronn

  • Resolution set to fixed
  • Status changed from assigned to closed

(In [11708]) [1.1.X] Fixed #12101 -- OGRGeometry does not need to create a clone of the SpatialReference object upon assignment.

Backport of r11707 from trunk.

comment:4 Changed 3 years ago by jacob

  • milestone 1.2 deleted

Milestone 1.2 deleted

Add Comment

Modify Ticket

Change Properties
<Author field>
Action
as closed
as The resolution will be set. Next status will be 'closed'
The resolution will be deleted. Next status will be 'new'
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.