-
Notifications
You must be signed in to change notification settings - Fork 15
Open
Labels
bugSomething isn't workingSomething isn't working
Description
Ubuntu 24.04.1 LTS
Version: 1.0.2-1noble.20250814.084246
Memory accumulates when creating Parser objects in a loop, even though the Parser goes out of scope at end of loop.
#include <fstream>
#include <iostream>
#include <string>
#include <memory>
#include <chrono>
#include <thread>
#include <rclcpp/serialized_message.hpp>
#include <rosx_introspection/ros_parser.hpp>
#include <rosx_introspection/ros_utils/ros2_helpers.hpp>
void print_memory_usage() {
std::ifstream statm("/proc/self/statm");
long size, resident;
statm >> size >> resident;
long page_size_kb = sysconf(_SC_PAGESIZE) / 1024;
std::cout << "Virtual Memory: " << size * page_size_kb << " KB\n";
std::cout << "Resident Memory: " << resident * page_size_kb << " KB\n";
}
int main() {
using namespace RosMsgParser;
const std::string topic = "dummy_topic";
const std::string type = "std_msgs/String";
size_t counter = 0;
std::vector<uint8_t> buffer(1024, 0);
// No leak
// Parser parser(topic, ROSType(type), GetMessageDefinition(type));
while (true) {
std::string out;
ROS2_Deserializer deserializer;
{
// leak
Parser parser(topic, ROSType(type), GetMessageDefinition(type));
Span<const uint8_t> span(buffer.data(), buffer.size());
parser.deserializeIntoJson(span, &out, &deserializer, 0, true);
}
counter++;
if (counter % 10000 == 0) {
print_memory_usage();
}
}
return 0;
}
Parser creation inside loop:
Virtual Memory: 12212 KB
Resident Memory: 9088 KB
Virtual Memory: 17236 KB
Resident Memory: 14080 KB
Virtual Memory: 22260 KB
Resident Memory: 19072 KB
Virtual Memory: 27352 KB
Resident Memory: 24192 KB
Virtual Memory: 32376 KB
Resident Memory: 29056 KB
Parser creation outside loop:
Virtual Memory: 7168 KB
Resident Memory: 4096 KB
Virtual Memory: 7264 KB
Resident Memory: 4096 KB
Virtual Memory: 7264 KB
Resident Memory: 4096 KB
Virtual Memory: 7264 KB
Resident Memory: 4096 KB
Virtual Memory: 7264 KB
Resident Memory: 4096 KB
From what I can decipher from valgrind the issue might be in BuildMessageSchema. I noticed very high memory usage in my generic bridge after it had been running in simulation for a day.
Copilot
Metadata
Metadata
Assignees
Labels
bugSomething isn't workingSomething isn't working