Calling Polygon.exterior creates noncollectable objects

View: New views
2 Messages — Rating Filter:   Alert me  

Calling Polygon.exterior creates noncollectable objects

by Jaakko Salli :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message


Hi all,

It seems that calling Polygon.exterior generates objects that are not
collectable even by gc.collect(). Attached script reproduces the issue.

Thanks,
  Jaakko




from shapely.geometry import Polygon

import random
import gc

from pprint import pprint

random.seed()
randint = random.randint

gc.enable()
gc.set_debug(gc.DEBUG_SAVEALL)

#
# For some reason, if iterations == 1, no uncollectable
# garbage is generated.
iterations = 2

#
# Let's build some dummy polygons and call their
# exterior property.
for i in range(0, iterations):
    points = []
    x0 = x = float(randint(-100, 100))
    y0 = y = float(randint(-100, 100))
    points.append((x, y))

    for n in range(0, randint(2, 10)):
        x += float(randint(0, 100))
        y += float(randint(0, 100))
        points.append((x, y))

    points.append((x0, y))
    points.append((x0, y0))

    poly = Polygon(points)
    poly.exterior

gc.collect()

pprint(gc.garbage)


_______________________________________________
Community mailing list
Community@...
http://lists.gispython.org/mailman/listinfo/community

Re: Calling Polygon.exterior creates noncollectable objects

by Sean Gillies :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Jaakko Salli wrote:
>
> Hi all,
>
> It seems that calling Polygon.exterior generates objects that are not
> collectable even by gc.collect(). Attached script reproduces the issue.
>
> Thanks,
>  Jaakko
>

Thanks for the report and script, Jaakko. There's a problem with
circular references here. I have a fix involving weak references, and
just need a day or two to test the cases of interior rings and sub-geoms
of the multipart types. Work around in the meantime is to break the
circular references in your code like:

    ...
    poly = Polygon(points)
    poly.exterior
    ...
    poly._exterior = None
    # end block

Sean

_______________________________________________
Community mailing list
Community@...
http://lists.gispython.org/mailman/listinfo/community
LightInTheBox - Buy quality products at wholesale price!