{"action":"created","issue":{"url":"https://api.github.com/repos/ThePhD/sol2/issues/129","repository_url":"https://api.github.com/repos/ThePhD/sol2","labels_url":"https://api.github.com/repos/ThePhD/sol2/issues/129/labels{/name}","comments_url":"https://api.github.com/repos/ThePhD/sol2/issues/129/comments","events_url":"https://api.github.com/repos/ThePhD/sol2/issues/129/events","html_url":"https://github.com/ThePhD/sol2/issues/129","id":162333110,"number":129,"title":"problem with std::shared_ptr's reference count","user":{"login":"Ung0d","id":20045290,"avatar_url":"https://avatars.githubusercontent.com/u/20045290?v=3","gravatar_id":"","url":"https://api.github.com/users/Ung0d","html_url":"https://github.com/Ung0d","followers_url":"https://api.github.com/users/Ung0d/followers","following_url":"https://api.github.com/users/Ung0d/following{/other_user}","gists_url":"https://api.github.com/users/Ung0d/gists{/gist_id}","starred_url":"https://api.github.com/users/Ung0d/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Ung0d/subscriptions","organizations_url":"https://api.github.com/users/Ung0d/orgs","repos_url":"https://api.github.com/users/Ung0d/repos","events_url":"https://api.github.com/users/Ung0d/events{/privacy}","received_events_url":"https://api.github.com/users/Ung0d/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/ThePhD/sol2/labels/Feature.AlreadyDone","name":"Feature.AlreadyDone","color":"fad8c7"}],"state":"open","locked":false,"assignee":{"login":"ThePhD","id":2886436,"avatar_url":"https://avatars.githubusercontent.com/u/2886436?v=3","gravatar_id":"","url":"https://api.github.com/users/ThePhD","html_url":"https://github.com/ThePhD","followers_url":"https://api.github.com/users/ThePhD/followers","following_url":"https://api.github.com/users/ThePhD/following{/other_user}","gists_url":"https://api.github.com/users/ThePhD/gists{/gist_id}","starred_url":"https://api.github.com/users/ThePhD/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ThePhD/subscriptions","organizations_url":"https://api.github.com/users/ThePhD/orgs","repos_url":"https://api.github.com/users/ThePhD/repos","events_url":"https://api.github.com/users/ThePhD/events{/privacy}","received_events_url":"https://api.github.com/users/ThePhD/received_events","type":"User","site_admin":false},"assignees":[{"login":"ThePhD","id":2886436,"avatar_url":"https://avatars.githubusercontent.com/u/2886436?v=3","gravatar_id":"","url":"https://api.github.com/users/ThePhD","html_url":"https://github.com/ThePhD","followers_url":"https://api.github.com/users/ThePhD/followers","following_url":"https://api.github.com/users/ThePhD/following{/other_user}","gists_url":"https://api.github.com/users/ThePhD/gists{/gist_id}","starred_url":"https://api.github.com/users/ThePhD/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ThePhD/subscriptions","organizations_url":"https://api.github.com/users/ThePhD/orgs","repos_url":"https://api.github.com/users/ThePhD/repos","events_url":"https://api.github.com/users/ThePhD/events{/privacy}","received_events_url":"https://api.github.com/users/ThePhD/received_events","type":"User","site_admin":false}],"milestone":{"url":"https://api.github.com/repos/ThePhD/sol2/milestones/4","html_url":"https://github.com/ThePhD/sol2/milestones/Already.Done","labels_url":"https://api.github.com/repos/ThePhD/sol2/milestones/4/labels","id":1766678,"number":4,"title":"Already.Done","description":"For the things that were preemptively finished.","creator":{"login":"ThePhD","id":2886436,"avatar_url":"https://avatars.githubusercontent.com/u/2886436?v=3","gravatar_id":"","url":"https://api.github.com/users/ThePhD","html_url":"https://github.com/ThePhD","followers_url":"https://api.github.com/users/ThePhD/followers","following_url":"https://api.github.com/users/ThePhD/following{/other_user}","gists_url":"https://api.github.com/users/ThePhD/gists{/gist_id}","starred_url":"https://api.github.com/users/ThePhD/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ThePhD/subscriptions","organizations_url":"https://api.github.com/users/ThePhD/orgs","repos_url":"https://api.github.com/users/ThePhD/repos","events_url":"https://api.github.com/users/ThePhD/events{/privacy}","received_events_url":"https://api.github.com/users/ThePhD/received_events","type":"User","site_admin":false},"open_issues":1,"closed_issues":5,"state":"open","created_at":"2016-05-15T04:11:15Z","updated_at":"2016-06-26T16:06:30Z","due_on":null,"closed_at":null},"comments":1,"created_at":"2016-06-26T15:42:53Z","updated_at":"2016-06-26T18:14:52Z","closed_at":null,"body":"When I copy a shared_ptr into lua and then setting the value to nil, the instance in lua is not destructed as expected. Any suggestions how to fix that other then using raw-ptrs for lua refs instead?\r\n\r\n```\r\n#include <sol.hpp>\r\n#include <iostream>\r\n#include <memory>\r\n\r\nstruct TestMe\r\n{\r\n    TestMe() {}\r\n    ~TestMe()\r\n    {\r\n        std::cout << \"DESTRUCTED\" << std::endl;\r\n    }\r\n};\r\n\r\nint main()\r\n{\r\n    auto test = std::make_shared<TestMe>();\r\n\r\n    sol::state lua;\r\n\r\n    lua[\"test\"] = test;\r\n    std::cout << test.use_count() << std::endl; //prints 2 since we just copied the ptr into lua\r\n    lua[\"test\"] = sol::nil;\r\n    std::cout << test.use_count() << std::endl; //still prints 2! why?\r\n\r\n    return 0;\r\n}\r\n```\r\n"},"comment":{"url":"https://api.github.com/repos/ThePhD/sol2/issues/comments/228614445","html_url":"https://github.com/ThePhD/sol2/issues/129#issuecomment-228614445","issue_url":"https://api.github.com/repos/ThePhD/sol2/issues/129","id":228614445,"user":{"login":"ThePhD","id":2886436,"avatar_url":"https://avatars.githubusercontent.com/u/2886436?v=3","gravatar_id":"","url":"https://api.github.com/users/ThePhD","html_url":"https://github.com/ThePhD","followers_url":"https://api.github.com/users/ThePhD/followers","following_url":"https://api.github.com/users/ThePhD/following{/other_user}","gists_url":"https://api.github.com/users/ThePhD/gists{/gist_id}","starred_url":"https://api.github.com/users/ThePhD/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ThePhD/subscriptions","organizations_url":"https://api.github.com/users/ThePhD/orgs","repos_url":"https://api.github.com/users/ThePhD/repos","events_url":"https://api.github.com/users/ThePhD/events{/privacy}","received_events_url":"https://api.github.com/users/ThePhD/received_events","type":"User","site_admin":false},"created_at":"2016-06-26T18:14:52Z","updated_at":"2016-06-26T18:14:52Z","body":"Because Lua runs on a Garbage Collection system and that might not trigger the \"DESTRUCTED\" until Lua deems that it needs to throw away that memory.\r\n\r\nNote that when the Lua State is destroyed, that destructor runs.\r\n\r\nIf you are uncomfortable with these semantics, you will have to look into manipulating the garbage collector with the `lua_gc` function and other functions. Even then, calling `lua_gc(lua, LUA_GCCOLLECT, 0);` does not mean that \"test\" will be cleaned up."}}
{"actor":{"display_login":"ThePhD"}}