Huge memory leak issue

Typically: "How do I... ", "How can I... " questions
Post Reply
atoz
Posts: 57
Joined: 18 Oct 2013, 09:02

Huge memory leak issue

Post by atoz » 29 Mar 2016, 17:30

Hi,

I'm getting a huge memory leak problem with the simRMLMoveToPosition method in my threaded script. I've narrowed it down to this method by using commenting and checking memory usage in system monitor. The memory usage increases by ~50Mb every 2 secs when the simulation is run and does not decrease until V-rep is shutdown. Any ideas? Thanks

The native system I'm using is:
Ubuntu 12.04 64-bit
Kernel Linux 3.8.0-44-generic
GNOME 3.4.2

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

Re: Huge memory leak issue

Post by coppelia » 30 Mar 2016, 09:11

Can you post a minimalistic scene that illustrates your problem?
It seems that even if that function was leaking memory, it would not be a large amount.

Cheers

atoz
Posts: 57
Joined: 18 Oct 2013, 09:02

Re: Huge memory leak issue

Post by atoz » 30 Mar 2016, 12:55

I have posted it on Dropbox: https://www.dropbox.com/s/i8jk50gvczl9z ... r.ttt?dl=0

I've tested it on Windows and it is the same as well. It doesn't happen with the built-in demos (reflexxesMotionLibraryType4Demo.ttt). But I can't see what is different on my version. I've tried to keep it the same.

Thanks

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

Re: Huge memory leak issue

Post by coppelia » 31 Mar 2016, 08:59

Ok, we can reproduce the memory leak. Thanks for mentioning this, this is actually a bug in our code. It was now corrected and will be available in next release (V3.3.1)

Why this has an impact in your scene and not in our scenes: in your threaded script, you call simRMLMoveToPosition continuously, even if the object is already in position/orientation. So the first time, the object will move into position, and all the next times, it will call simRMLMoveToPosition and exit directly, leaving a memory leak each time.

As a quick work around, you can first test whether your object is already in position or not. For that, simply compare the position AND orientation between your object frame, and the target position/orientation.

Position differences can be computed via simGetObjectPosition and subtracting with the target position, and checking the vector length. If the vector length is below a specific threshold, then you are in position.

Orientational differences can be computed via simGetRotationAxis. If the rotation angle is below a certain threshold, then you have the same orientation. You will additionally need following API functions too: simGetObjectMatrix and maybe also simBuildMatrix or simBuildMatrixQ.

Thanks again for finding that bug!

Cheers

atoz
Posts: 57
Joined: 18 Oct 2013, 09:02

Re: Huge memory leak issue

Post by atoz » 31 Mar 2016, 15:07

Thanks for your help with the workaround. I have implemented it and it seems to be working.

I also wanted to know if there was a way to use the reflexxes library in a non-blocking manner. Currently the simRMLMoveToPosition blocks and this is not suitable for teleoperation purposes.

Cheers

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

Re: Huge memory leak issue

Post by coppelia » 01 Apr 2016, 10:42

Yes, if you want to use the Reflexxes library in a non-blocking manner, you should use following functions instead:
Cheers

atoz
Posts: 57
Joined: 18 Oct 2013, 09:02

Re: Huge memory leak issue

Post by atoz » 04 Apr 2016, 19:33

coppelia wrote:Yes, if you want to use the Reflexxes library in a non-blocking manner, you should use following functions instead:
">http://www.coppeliarobotics.com/helpFil ... Remove.htm]simRMLRemove[/url][/list]</a>

Cheers
Is there any further documentation or examples for these methods? I don't understand some things such as:

- selection parameter for simRMLPos- what is this? what values should it hold?
- cycle time in simRMLStep?

As I understand it, to move with these methods, a trajectory is generated with simRMLPos and then executed in a loop with simRMLStep. If I want to change the trajectory during execution, how would I accomplish that?

Thanks

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

Re: Huge memory leak issue

Post by coppelia » 05 Apr 2016, 10:14

The selection parameter can be used to exclude specific dimensions from the calculation. You shouldn't use it, unless you do something very special.

The cycleTime parameter is normally simply the simulation time step (i.e. simGetSimulationTimeStep() )

Here a simple example (for 3 DoFs) that runs in a threaded child script (but you can make a similar example in a non-threaded child script):

Code: Select all

    rmlHandle=simRMLPos(3,0.0001,-1,posVelAccel,maxVelAccelJerk,{1,1,1},targetPosVel)
    while res==0 do
        dt=simGetSimulationTimeStep()
        res,posVelAccel,sync=simRMLStep(rmlHandle,dt)
        if (res>=0) then
            -- We reached the end of the movement
            break
        end
        simSwitchThread()
    end
    simRMLRemove(rmlHandle)
The trajectory is not generated with simRMLPos. It is just initialized. But currently you cannot modify the various parameters between simRMLStep calls.

Cheers

Post Reply