deleting a map does not release the corresponding memory from RAM.

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

deleting a map does not release the corresponding memory from RAM.

Amber
Hi Matheu,

Problem: I have a map loaded while running localization with rtabmap node. Now, without crashing the node, I want to remove that map_1.db file and load another one, say map_2.db.


This process somewhat works, although there is a problem situation.
Situation:
Initially, map_1.db is loaded. Then, I use rtabmap.close() (important one only mentioned) function to delete the memory occupied by the map and through a ros service call load map_2.db (I also call OnInit() function through this service). However, my RAM usage shows that the space occupied by map_1.db is not freed.

Would you please suggest, if I am missing something?

regards,
Anindya
Reply | Threaded
Open this post in threaded view
|

Re: deleting a map does not release the corresponding memory from RAM.

Amber
Hi Matheu,

The issue mentioned in the above message is still there. I would like to further explain it. I play with the OnInit() function. I created a service (that passes the new map path) that once called, will delete the old map by calling _rtabmap.close(). Then, it would call _rtabmap.init() so that the new map can be loaded. The problem is that although the old map data do not persist in the program, but it is not released from the RAM. I looked into it in detail. I find that _dbDriver->loadSignatures(...)is causing a part of it. I tried to delete the Signature pointers first from the dbSignatures and then remove it, but the memory is still not freed. I tried to replace std::list<Signature*> with std::vector<Signature*>. But still no success. The memory is released only when rtabmap node is crashed. Even calling ~Rtabmap() and ~Memory() do not help it seems. That means, even if I don't call _rtabmap.Init() again and just call _rtabmap.close(), that does not release the memory occupied by the previous map. This is very surprising to me. May I request your observation on this?

thanks,
 
Reply | Threaded
Open this post in threaded view
|

Re: deleting a map does not release the corresponding memory from RAM.

matlabbe
Administrator
Hi,

did you look at the load_database service? Here is the code to cleanup everything: https://github.com/introlab/rtabmap_ros/blob/1e28de0b38d20410d47fb9fb5d4c8d96f1590c5d/src/CoreWrapper.cpp#L2930

In particular, mapsManager_.clear() should be called, as it can hold a lot of memory.

cheers,
Mathieu
Reply | Threaded
Open this post in threaded view
|

Re: deleting a map does not release the corresponding memory from RAM.

Amber
This post was updated on .
Hi Mathieu,

Thank you for your response. I tried with rtabmap_ros-0.20.18-noetic. Unfortunately, it did not help. Please see a small demo video for the same. I used three .db files with the following sizes.


map_1.db (790MB)
map_2.db (1.5GB)
map_3.db (1.4GB)

I expect that when a new .db will be loaded the memory occupied by the previous .db will be released which is not happening.
p.s.
map_2 and map_3 have a lot of overlap in terms of the occupancy grid covered in the map.

Also, it may not be significant, but the .db file was prepared from an older version of rtabmap.

I also commented out a portion from loadDatabaseCallback(...) in CoreWrapper.cpp to just close rtabmap and not initialize again. I see that it does not release any memory.


I observed that,
at L243 from Memory.cpp, these signatures once loaded are not being released, even though I follow the routine written in the loadDatabaseCallback().

_dbDriver->loadSignatures(std::list<int>(ids.begin(), ids.end()), dbSignatures);

One doubt comes to my mind. Is there any memory leakage in DBDriverSqlite3.cpp?

Please suggest.

Thank you,
Reply | Threaded
Open this post in threaded view
|

Re: deleting a map does not release the corresponding memory from RAM.

matlabbe
Administrator
Hi,

If I see correctly in the video, your total memory increases from 4.3 to 5.8 when loading databases. If there was a leak, the memory would increase to 8GB (sum of three databases). 5.8-4.3=1.5GB, which is the size of the largest database.

If you load map_2.db first, you will have 5.8 GB usage. If you unload and load map_1.db, the memory usage will still appear 5.8 GB, but internally, it has cleared and re-used some of that memory. I think linux won't show released memory in Top, but internally the memory is available. To better estimate the real memory used, you should use tools like valgrind's massif tool like in this post: https://github.com/introlab/rtabmap/issues/494

cheers,
Mathieu