{"action":"created","issue":{"url":"https://api.github.com/repos/orocos-toolchain/typelib/issues/31","labels_url":"https://api.github.com/repos/orocos-toolchain/typelib/issues/31/labels{/name}","comments_url":"https://api.github.com/repos/orocos-toolchain/typelib/issues/31/comments","events_url":"https://api.github.com/repos/orocos-toolchain/typelib/issues/31/events","html_url":"https://github.com/orocos-toolchain/typelib/issues/31","id":53536401,"number":31,"title":"Memory leak in typelib container type","user":{"login":"saarnold","id":7925487,"avatar_url":"https://avatars.githubusercontent.com/u/7925487?v=3","gravatar_id":"","url":"https://api.github.com/users/saarnold","html_url":"https://github.com/saarnold","followers_url":"https://api.github.com/users/saarnold/followers","following_url":"https://api.github.com/users/saarnold/following{/other_user}","gists_url":"https://api.github.com/users/saarnold/gists{/gist_id}","starred_url":"https://api.github.com/users/saarnold/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/saarnold/subscriptions","organizations_url":"https://api.github.com/users/saarnold/orgs","repos_url":"https://api.github.com/users/saarnold/repos","events_url":"https://api.github.com/users/saarnold/events{/privacy}","received_events_url":"https://api.github.com/users/saarnold/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":4,"created_at":"2015-01-06T17:02:27Z","updated_at":"2015-01-07T15:53:09Z","closed_at":null,"body":"While converting old to new types using the rock log converter, I stumbled over a possible memory leak. Apparently it happens when elements are added to a std/vector container. This small script reveals the problem:\r\n\r\n```ruby\r\nrequire 'orocos'\r\nrequire 'readline'\r\ninclude Orocos\r\nOrocos.initialize\r\n\r\ndef create_objects(typename, object_count, element_count)\r\n    registry = Orocos.registry\r\n    object_count.times { \r\n        puts \"Create new object\"\r\n        type = registry.get(typename).new \r\n        element_count.times { type.ranges.push 0 }\r\n        #element_count.times { type.ranges.do_push 0 }\r\n\r\n        size = `ps -o rss -p #{$$}`.chomp.split(\"\\n\").last.to_i / 1024\r\n        puts \"Memory usage: \" + size.to_s + \" MB\"\r\n        puts \"Object losses reference\"\r\n    }\r\nend\r\n\r\ntype_name = '/base/samples/LaserScan'\r\nOrocos.load_typekit_for type_name\r\n\r\nsize = `ps -o rss -p #{$$}`.chomp.split(\"\\n\").last.to_i / 1024\r\nputs \"Memory usage start: \" + size.to_s + \" MB\"\r\n\r\ncreate_objects(type_name, 10, 100000)\r\n\r\n#Manually run GC\r\nGC.start\r\n\r\nsize = `ps -o rss -p #{$$}`.chomp.split(\"\\n\").last.to_i / 1024\r\nputs \"Memory usage end: \" + size.to_s + \" MB\"\r\n\r\nputs \"Press enter to exit.\"\r\nReadline.readline\r\n```\r\nUsing the direct c binding do_push works perfectly fine. Using push is way slower and the GC does not free all objects. \r\n\r\nSo when converting log files my complete memory runs full. Currently I'm using an FFI::MemoryPointer and raw_memcpy to tackle the problem.\r\n\r\nPS: I'm using 14.04 and the master branch."},"comment":{"url":"https://api.github.com/repos/orocos-toolchain/typelib/issues/comments/69041423","html_url":"https://github.com/orocos-toolchain/typelib/issues/31#issuecomment-69041423","issue_url":"https://api.github.com/repos/orocos-toolchain/typelib/issues/31","id":69041423,"user":{"login":"saarnold","id":7925487,"avatar_url":"https://avatars.githubusercontent.com/u/7925487?v=3","gravatar_id":"","url":"https://api.github.com/users/saarnold","html_url":"https://github.com/saarnold","followers_url":"https://api.github.com/users/saarnold/followers","following_url":"https://api.github.com/users/saarnold/following{/other_user}","gists_url":"https://api.github.com/users/saarnold/gists{/gist_id}","starred_url":"https://api.github.com/users/saarnold/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/saarnold/subscriptions","organizations_url":"https://api.github.com/users/saarnold/orgs","repos_url":"https://api.github.com/users/saarnold/repos","events_url":"https://api.github.com/users/saarnold/events{/privacy}","received_events_url":"https://api.github.com/users/saarnold/received_events","type":"User","site_admin":false},"created_at":"2015-01-07T15:53:09Z","updated_at":"2015-01-07T15:53:09Z","body":"Your fix works perfectly fine. Thanks!"}}