simGetVisionSensorxxxx() memory leak

Typically: "How do I... ", "How can I... " questions
Post Reply
ryt
Posts: 13
Joined: 04 Jan 2014, 12:45
Location: Taipei

simGetVisionSensorxxxx() memory leak

Post by ryt » 24 Jan 2014, 14:23

Hello
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"?

Thanks

coppelia
Site Admin
Posts: 6766
Joined: 14 Dec 2012, 00:25

Re: simGetVisionSensorxxxx() memory leak

Post by coppelia » 24 Jan 2014, 14:46

Hello,

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.

Cheers

ryt
Posts: 13
Joined: 04 Jan 2014, 12:45
Location: Taipei

Re: simGetVisionSensorxxxx() memory leak

Post by ryt » 24 Jan 2014, 17:47

OK, but my pointer is float. The simreleasebuffer parse char pointer. It will show error in plugin compiling..

coppelia
Site Admin
Posts: 6766
Joined: 14 Dec 2012, 00:25

Re: simGetVisionSensorxxxx() memory leak

Post by coppelia » 24 Jan 2014, 18:01

You should cast the pointer to (char*)

Cheers

markusi
Posts: 11
Joined: 19 Apr 2013, 09:47

Re: simGetVisionSensorxxxx() memory leak

Post by markusi » 18 Jul 2018, 15:59

Hello,

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.

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

I may face a memory leak problem with simIM (see also https://github.com/CoppeliaRobotics/v_r ... e/issues/1)

I tried to free memory like below:

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

but that doesn't help.

Any suggestions ?

coppelia
Site Admin
Posts: 6766
Joined: 14 Dec 2012, 00:25

Re: simGetVisionSensorxxxx() memory leak

Post by coppelia » 20 Jul 2018, 07:34

Hello,

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

Cheers

Post Reply