{"action":"created","issue":{"url":"https://api.github.com/repos/JuliaStats/RCall.jl/issues/14","labels_url":"https://api.github.com/repos/JuliaStats/RCall.jl/issues/14/labels{/name}","comments_url":"https://api.github.com/repos/JuliaStats/RCall.jl/issues/14/comments","events_url":"https://api.github.com/repos/JuliaStats/RCall.jl/issues/14/events","html_url":"https://github.com/JuliaStats/RCall.jl/issues/14","id":54121043,"number":14,"title":"asSEXP may need 'PreserveObject'","user":{"login":"randy3k","id":1690993,"avatar_url":"https://avatars.githubusercontent.com/u/1690993?v=3","gravatar_id":"","url":"https://api.github.com/users/randy3k","html_url":"https://github.com/randy3k","followers_url":"https://api.github.com/users/randy3k/followers","following_url":"https://api.github.com/users/randy3k/following{/other_user}","gists_url":"https://api.github.com/users/randy3k/gists{/gist_id}","starred_url":"https://api.github.com/users/randy3k/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/randy3k/subscriptions","organizations_url":"https://api.github.com/users/randy3k/orgs","repos_url":"https://api.github.com/users/randy3k/repos","events_url":"https://api.github.com/users/randy3k/events{/privacy}","received_events_url":"https://api.github.com/users/randy3k/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":5,"created_at":"2015-01-12T23:11:23Z","updated_at":"2015-01-13T21:45:17Z","closed_at":null,"body":"https://github.com/JuliaStats/RCall.jl/blob/b4afdd6d76f3e2f690cace4b242b1d9c0643c767/src/sexp.jl#L140\r\n\r\nI believe that we have to somehow preserve the object created by Rf_allocVector.\r\nIt should be fine if this R object is blinded to some variable in some environment. But it may not be always the case.\r\nFor example, the following produces segfault\r\n```\r\nx  = RCall.asSEXP([1:10^8])\r\nfor i in 1:10\r\n   Reval(Rparse(\"gc()\"))\r\nend\r\nRprint(x)\r\n```\r\n\r\n\r\n"},"comment":{"url":"https://api.github.com/repos/JuliaStats/RCall.jl/issues/comments/69826389","html_url":"https://github.com/JuliaStats/RCall.jl/issues/14#issuecomment-69826389","issue_url":"https://api.github.com/repos/JuliaStats/RCall.jl/issues/14","id":69826389,"user":{"login":"randy3k","id":1690993,"avatar_url":"https://avatars.githubusercontent.com/u/1690993?v=3","gravatar_id":"","url":"https://api.github.com/users/randy3k","html_url":"https://github.com/randy3k","followers_url":"https://api.github.com/users/randy3k/followers","following_url":"https://api.github.com/users/randy3k/following{/other_user}","gists_url":"https://api.github.com/users/randy3k/gists{/gist_id}","starred_url":"https://api.github.com/users/randy3k/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/randy3k/subscriptions","organizations_url":"https://api.github.com/users/randy3k/orgs","repos_url":"https://api.github.com/users/randy3k/repos","events_url":"https://api.github.com/users/randy3k/events{/privacy}","received_events_url":"https://api.github.com/users/randy3k/received_events","type":"User","site_admin":false},"created_at":"2015-01-13T21:45:17Z","updated_at":"2015-01-13T21:45:17Z","body":"Actually, the bottleneck can be easily seen by \r\n```\r\njulia> @time for i in 1:100000 RCall.asSEXP([1:10]) end\r\nelapsed time: 0.44483907 seconds (26656472 bytes allocated, 68.26% gc time)\r\n\r\njulia> @time for i in 1:100000 RCall.asSEXP([1:10]) end\r\nelapsed time: 144.245652407 seconds (28945552 bytes allocated, 99.90% gc time)\r\n```\r\n\r\nThe second run is **extremely** slow since GC is freeing the memory allocated by the first run."}}