New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Memory leak with PShape #233

Closed
K2017 opened this Issue Jan 22, 2017 · 8 comments

Comments

Projects
None yet
4 participants
@K2017

K2017 commented Jan 22, 2017

There seems to be an issue regarding the way memory is reclaimed after a sketch is closed in python mode; and it seems it is related to PShapes remaining in memory.

Example Sketch:

def setup():
    size(200, 200, OPENGL)
    global MAP
    MAP = ShapeTest()
    MAP.CompileMap()
 
def draw():
    background(0)
    translate(width/2, height/2, 10)
    shape(MAP.Get(), 0, 0)
 
class ShapeTest(object):
    def __init__(self):
        self.Size = 200
 
        self.Map = createShape(GROUP)
 
    def CompileMap(self):
 
        S = 10
 
        for i in range(self.Size):
            for j in range(self.Size):
 
                TileSet = createShape()
                TileSet.beginShape(QUAD)
 
                TileSet.vertex(S + 2*S*i, S + 2*S*j, 0)
                TileSet.vertex(S + 2*S*i, -S + 2*S*j, 0)
                TileSet.vertex(-S + 2*S*i, -S + 2*S*j, 0)
                TileSet.vertex(-S + 2*S*i, S + 2*S*j, 0)
 
                TileSet.endShape()
 
                self.Map.addChild(TileSet)
 
    def Get(self):
        return self.Map

Repeatedly running this sketch will eventually cause a 'GC overhead limit' OOME or a 'Java heap space' OOME due to the sketch process remaining active.

@jdf

This comment has been minimized.

Show comment
Hide comment
@jdf

jdf Jan 22, 2017

Owner

Very interesting, and I can vaguely guess why it's happening.

If you add

def dispose():
    global MAP
    MAP = None

does it mitigate the problem?

Owner

jdf commented Jan 22, 2017

Very interesting, and I can vaguely guess why it's happening.

If you add

def dispose():
    global MAP
    MAP = None

does it mitigate the problem?

@jdf jdf self-assigned this Jan 22, 2017

@K2017

This comment has been minimized.

Show comment
Hide comment
@K2017

K2017 Jan 22, 2017

Sadly it does not. I have tested object (and PShape + PImage) deletion on both stop() and dispose(), but the problem persists.

K2017 commented Jan 22, 2017

Sadly it does not. I have tested object (and PShape + PImage) deletion on both stop() and dispose(), but the problem persists.

@K2017

This comment has been minimized.

Show comment
Hide comment
@K2017

K2017 Jan 22, 2017

Even simpler case without classes or functions:

def setup():
    size(200, 200, OPENGL)
    global Map
    Size = 200
    S = 10
    Map = createShape(GROUP)

    for i in range(Size):
        for j in range(Size):
            
            TileSet = createShape()
            TileSet.beginShape(QUAD)
            
            TileSet.vertex(S + 2*S*i, S + 2*S*j, 0)
            TileSet.vertex(S + 2*S*i, -S + 2*S*j, 0)
            TileSet.vertex(-S + 2*S*i, -S + 2*S*j, 0)
            TileSet.vertex(-S + 2*S*i, S + 2*S*j, 0)
                
            TileSet.endShape()

            Map.addChild(TileSet)
    
def draw():
    background(0)
    translate(width/2, height/2, 10)
    shape(Map, 0, 0)

K2017 commented Jan 22, 2017

Even simpler case without classes or functions:

def setup():
    size(200, 200, OPENGL)
    global Map
    Size = 200
    S = 10
    Map = createShape(GROUP)

    for i in range(Size):
        for j in range(Size):
            
            TileSet = createShape()
            TileSet.beginShape(QUAD)
            
            TileSet.vertex(S + 2*S*i, S + 2*S*j, 0)
            TileSet.vertex(S + 2*S*i, -S + 2*S*j, 0)
            TileSet.vertex(-S + 2*S*i, -S + 2*S*j, 0)
            TileSet.vertex(-S + 2*S*i, S + 2*S*j, 0)
                
            TileSet.endShape()

            Map.addChild(TileSet)
    
def draw():
    background(0)
    translate(width/2, height/2, 10)
    shape(Map, 0, 0)

@K2017 K2017 changed the title from Incorrect Sketch Disposal on stop() to Improper Sketch Disposal on stop() Jan 22, 2017

@jeremydouglass

This comment has been minimized.

Show comment
Hide comment
@jeremydouglass

jeremydouglass Jan 22, 2017

Also some discussion of this on the forum, here: https://forum.processing.org/two/discussion/1202/pshape-memory-leak-garbage-collection-pauses

I'm not sure if it is useful but I wrote a Java version of the original test sketch there which did not exhibit the same problem.

jeremydouglass commented Jan 22, 2017

Also some discussion of this on the forum, here: https://forum.processing.org/two/discussion/1202/pshape-memory-leak-garbage-collection-pauses

I'm not sure if it is useful but I wrote a Java version of the original test sketch there which did not exhibit the same problem.

@jdf

This comment has been minimized.

Show comment
Hide comment
@jdf

jdf Jan 23, 2017

Owner

Does this happen with a non-OPENGL renderer?

Owner

jdf commented Jan 23, 2017

Does this happen with a non-OPENGL renderer?

@K2017

This comment has been minimized.

Show comment
Hide comment
@K2017

K2017 Jan 23, 2017

I can confirm the problem occurs using JAVA2D as well. There seems to be an unrelated issue using FX2D however (A 'connection reset' error on sketch stop), which kills the sketch runner, so I could not test whether the problem occurs with FX2D.

K2017 commented Jan 23, 2017

I can confirm the problem occurs using JAVA2D as well. There seems to be an unrelated issue using FX2D however (A 'connection reset' error on sketch stop), which kills the sketch runner, so I could not test whether the problem occurs with FX2D.

@jdf jdf changed the title from Improper Sketch Disposal on stop() to Memory leak with PShape Feb 9, 2017

@jdf

This comment has been minimized.

Show comment
Hide comment
@jdf

jdf Jul 8, 2017

Owner

Seems to be fixed. Please reopen if necessary.

Owner

jdf commented Jul 8, 2017

Seems to be fixed. Please reopen if necessary.

@jdf jdf closed this Jul 8, 2017

@neilcsmith-net

This comment has been minimized.

Show comment
Hide comment
@neilcsmith-net

neilcsmith-net Aug 8, 2017

VisualVM suggests this issue still exists as per my comment on the pull request above.

neilcsmith-net commented Aug 8, 2017

VisualVM suggests this issue still exists as per my comment on the pull request above.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment