Memory leak

Hi,

I compile the code:

#include "pandaFramework.h"
#include "pandaSystem.h"
 
int main(int argc, char *argv[]) {
    //open a new window framework
  PandaFramework framework;
  framework.open_framework(argc, argv);
    //set the window title to My Panda3D Window
  framework.set_window_title("My Panda3D Window");
    //open the window
  WindowFramework *window = framework.open_window();
 
  //here is room for your own code
 
    //do the main loop, equal to run() in python
  framework.main_loop();
    //close the window framework
  framework.close_framework();
  return (0);
}

Leading to leakage of 0.004 kb 1 sec.

Compiler Options:

-------------- Build: Release in TestPanda3D (compiler: Microsoft Visual C++ 2010)---------------

cl.exe /nologo /O2 /EHsc  /MD /DNDEBUG    /IC:\Panda3D-1.9.2-x64\include /IC:\Panda3D-1.9.2-x64\python\include /I"C:\Program Files\Microsoft SDKs\Windows\v7.1\Include" /I"C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\include" /c main.cpp /Foobj\Release\main.obj
main.cpp
link.exe /nologo /LIBPATH:C:\Panda3D-1.9.2-x64\lib /LIBPATH:C:\Panda3D-1.9.2-x64\python\libs /LIBPATH:"C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\lib\amd64" /LIBPATH:"C:\Program Files\Microsoft SDKs\Windows\v7.1\Lib\x64" /LIBPATH:"C:\Program Files\Microsoft SDKs\Windows\v7.1\Lib" /LIBPATH:"C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\lib" /out:bin\Release\TestPanda3D.exe libp3framework.lib libpanda.lib libpandaexpress.lib libp3dtool.lib libp3dtoolconfig.lib libp3pystub.lib libp3direct.lib obj\Release\main.obj  
Output file is bin\Release\TestPanda3D.exe with size 11.50 KB
Process terminated with status 0 (0 minute(s), 30 second(s))
0 error(s), 0 warning(s) (0 minute(s), 30 second(s))

I watched through the Task Manager

As a heads up, Windows Task Manager is not always the best way to check for memory leaks (especially down to 0.004kb). Something like Valgrind’s memcheck tool or Visual Leak Detector are usually much more accurate (and can help pinpoint the leak). As such, I wouldn’t expect much effort from devs to go into investigating or developing a “fix” of some sort without more data.

The question is that is it just me? Memory consumption increases and it is clear to the eye.

0.004kb per second (approximately)

Ah, I wasn’t aware that it continues to rise. That does sound a little worrying, and it would probably be worth investigating with a leak checker.

You will not believe the code from the textbook has a memory leak. :open_mouth:

#include "pandaFramework.h"
#include "pandaSystem.h"
 
int main(int argc, char *argv[]) {
    //open a new window framework
  PandaFramework framework;
  framework.open_framework(argc, argv);
    //set the window title to My Panda3D Window
  framework.set_window_title("My Panda3D Window");
    //open the window
  WindowFramework *window = framework.open_window();
 
  //here is room for your own code
 
    //do the main loop, equal to run() in python
  framework.main_loop();
    //close the window framework
  framework.close_framework();
  return (0);
}

However, if I supplement my code, it’s OK.

Example:

#include "pandaFramework.h"
#include "pandaSystem.h"
#include "geomTristrips.h"

void CubeToSphere (LVector3f&vPosition){

    float x2 = vPosition[0] * vPosition[0] ;
    float y2 = vPosition[1] * vPosition[1] ;
    float z2 = vPosition[2] * vPosition[2];

    vPosition[0] = vPosition[0] * sqrt( 1.0f - ( y2 * 0.5f ) - ( z2 * 0.5f ) + ( (y2 * z2) / 3.0f ) );
    vPosition[1] = vPosition[1] * sqrt( 1.0f - ( z2 * 0.5f ) - ( x2 * 0.5f ) + ( (z2 * x2) / 3.0f ) );
    vPosition[2] = vPosition[2] * sqrt( 1.0f - ( x2 * 0.5f ) - ( y2 * 0.5f ) + ( (x2 * y2) / 3.0f ) );
}

int main(int argc, char *argv[]) {
PandaFramework framework;
framework.open_framework(argc, argv);
framework.set_window_title("My Panda3D");
WindowFramework *window = framework.open_window();
window->setup_trackball();

PT(GeomVertexData) vdata;
vdata = new GeomVertexData("ProceduralMesh", GeomVertexFormat::get_v3(), Geom::UH_static);

vdata->set_num_rows(4);

GeomVertexWriter vertex; vertex = GeomVertexWriter(vdata, "vertex");

PT(GeomTristrips) prim;
prim = new GeomTristrips(Geom::UH_static);

int height  = 2;
int width  =  2;
float  radius = 3.0;

LVector3f vMinPosition(-1.0f, -1.0f, 0.0f );

int index = 0;

for ( int  y  =  0;  y < height; ++y){
    for ( int  x  = 0;  x < width;  ++x ){

        LVector3f vPosition = vMinPosition;

        vPosition[0] += (float)x / (float)(width-1)* 2.0f;
        vPosition[1] +=- (float)y / (float)(height-1)* 2.0f;

        vertex.add_data3f(vPosition);

        prim->add_vertex( index);

        if ( index ==  3){
            prim->close_primitive();
            index = 0;
        }

       ++ index ;

        }
}

PT(Geom) geom;
geom = new Geom(vdata);
geom->add_primitive(prim);

PT(GeomNode) node;
node = new GeomNode("gnode");
node->add_geom(geom);

NodePath nodePath = window->get_render().attach_new_node(node);

framework.main_loop();
framework.close_framework();
return (0);
}

No Leaks :laughing: