Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Memory leak in glutSolidSphere?



On 26 May 2005, at 14:24, Theo Vosse wrote:

Hi,

I've noticed that calling glutSolidSphere() seems to leak memory. Launching the application with MallocDebug shows an increase in leaks every time I draw one. In particular, it allocates these quadrics, but apparently never releases them.

Am I doing something wrong or is this a bug?

Thanks in advance,

    Theo



Apple's GLUT implementation is available at: http://developer.apple.com/samplecode/glut/glut.html

I had a quick look through the code for glutSolidSphere (from glut_shapes.c) and have included some relevant bits at the end.

Basically, GLUT is implemented as a subclassed NSOpenGLView with an instance variable _quadObj which is shared by all GLUT related calls. However, this only gets deallocated when the application closes (via the dealloc method). If you want memory deallocated before application termination then I guess you have to implement this yourself using the GLU APIs like gluSphere.





#define QUAD_OBJ_INIT() GLUquadricObj *quadObj =  __glutGetQuadObj();

void APIENTRY
glutSolidSphere(GLdouble radius, GLint slices, GLint stacks)
{
  QUAD_OBJ_INIT();
  gluQuadricDrawStyle(quadObj, GLU_FILL);
  gluQuadricNormals(quadObj, GLU_SMOOTH);
  /* If we ever changed/used the texture or orientation state
     of quadObj, we'd need to change it to the defaults here
     with gluQuadricTexture and/or gluQuadricOrientation. */
  gluSphere(quadObj, radius, slices, stacks);
}

// A helper for quadric objects
GLUquadricObj *__glutGetQuadObj(void)
{
if (__glutViewList == NULL) // This means you never initialized GLUT - BUT you are still allowed to call glutWireShphere()
// and such anyway. Fixes bug #2742838
return gluNewQuadric();


    return [__glutCurrentView _getQuadObj];
}

- (GLUquadricObj *)_getQuadObj
{
    if (_quadObj == NULL)
        _quadObj = gluNewQuadric();
    return _quadObj;
}



r i c k
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Mac-opengl mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/mac-opengl/email@hidden

This email sent to email@hidden
References: 
 >Memory leak in glutSolidSphere? (From: Theo Vosse <email@hidden>)



Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.