Page 1 of 1

simGetVisionSensorxxxx() memory leak

Posted: 24 Jan 2014, 14:23
by ryt
I wrote down a plugin to create a LUA custom function. This function tried to acces vision sensor data using simGetVisionSensorDepthBuffer() and simGetVisionSensorImage(). As I run my plugin in simulation, my memory consumption continuously increased and reached maximum. I did some checking through all line in my code and found out that the leak sources are those two functions. The part of my code is shown below.

Code: Select all

float *depth_image, *color_image;
depth_image = simGetVisionSensorDepthBuffer(vision_handler);
color_image = simGetVisionSensorImage(vision_handler);
I have tried to free() those pointer, but it return an exception. Is there any solution for this?
Is it related with the C-return value explanation in API section of simGetVisionSensorImage() --> "The user is in charge of releasing the returned buffer with simReleaseBuffer"?


Re: simGetVisionSensorxxxx() memory leak

Posted: 24 Jan 2014, 14:46
by coppelia

If I understood you correctly, your cutom Lua function is calling the vision sensor functions via a plugin, in C/C++, right?

The C/C++ version of the simGetVisionSensorDepthBuffer and simGetVisionSensorImage functions require you to destroy the returned buffers via the simReleaseBuffer functions. free, delete or delete[] will not work and leads to possible crashes.


Re: simGetVisionSensorxxxx() memory leak

Posted: 24 Jan 2014, 17:47
by ryt
OK, but my pointer is float. The simreleasebuffer parse char pointer. It will show error in plugin compiling..

Re: simGetVisionSensorxxxx() memory leak

Posted: 24 Jan 2014, 18:01
by coppelia
You should cast the pointer to (char*)


Re: simGetVisionSensorxxxx() memory leak

Posted: 18 Jul 2018, 15:59
by markusi

I want to access a vision sensor several times during a simulation.
Therefore I extended the robot lua script to save some Vision Sensor images to the HDD. That works pretty well but memory usage grows over time causing system crashes.

local img_handle = simIM.readFromVisionSensor(visionsensorHandle)
local imgfilename = "d:\\data\\" .. imagenumber .. ".jpg"

I may face a memory leak problem with simIM (see also ... e/issues/1)

I tried to free memory like below:

simimhandles = simIM.handles()
for i in pairs(simimhandles) do

but that doesn't help.

Any suggestions ?

Re: simGetVisionSensorxxxx() memory leak

Posted: 20 Jul 2018, 07:34
by coppelia

there was indeed a memory leak in the image plugin. Did you try to recompile the plugin after that?