{"action":"created","issue":{"url":"https://api.github.com/repos/Zeex/pawn/issues/95","repository_url":"https://api.github.com/repos/Zeex/pawn","labels_url":"https://api.github.com/repos/Zeex/pawn/issues/95/labels{/name}","comments_url":"https://api.github.com/repos/Zeex/pawn/issues/95/comments","events_url":"https://api.github.com/repos/Zeex/pawn/issues/95/events","html_url":"https://github.com/Zeex/pawn/issues/95","id":151842776,"number":95,"title":"Ability to create destructors for tags [FEATURE REQUEST]","user":{"login":"YashasSamaga","id":6652578,"avatar_url":"https://avatars.githubusercontent.com/u/6652578?v=3","gravatar_id":"","url":"https://api.github.com/users/YashasSamaga","html_url":"https://github.com/YashasSamaga","followers_url":"https://api.github.com/users/YashasSamaga/followers","following_url":"https://api.github.com/users/YashasSamaga/following{/other_user}","gists_url":"https://api.github.com/users/YashasSamaga/gists{/gist_id}","starred_url":"https://api.github.com/users/YashasSamaga/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/YashasSamaga/subscriptions","organizations_url":"https://api.github.com/users/YashasSamaga/orgs","repos_url":"https://api.github.com/users/YashasSamaga/repos","events_url":"https://api.github.com/users/YashasSamaga/events{/privacy}","received_events_url":"https://api.github.com/users/YashasSamaga/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":9,"created_at":"2016-04-29T11:08:20Z","updated_at":"2016-05-02T16:17:59Z","closed_at":null,"body":"I apologize for giving such a vague title. Anyway the suggestion is to allow the scripter to create destructors for tagged variables. The destructor (if defined) should be called every time a variable  is pulled out of the stack or goes out of scope.\r\n\r\n` stock ~Mytag(Mytag:mytag) { }`\r\n\r\nIt is extremely extremely extremely useful (this is an understatement) especially for those who write plugins. \r\n\r\n**Why is this needed?** \r\nRight now, my plugin calls a public in every script every second which in turn calls a native. This native destroys all local lists/vectors/etc that were created in the script which called the native. If someone creates 10k lists in a loop, the server starts hanging for minutes but it doesn't happen if I destroy the list after its use (no idea why creating lot of them at once hangs the server but creating and destroying after use doesn't cause the server to hang).\r\n\r\nIf support for making destructors is added, it will help in reducing the memory footprint as well as improve performance (not sure if that is significant).\r\n\r\nIt will also help in PAWN includes too. For example, INI_Close can be executed automatically once the variable with INI tag goes out of scope instead of expecting the user to do INI_Close every time."},"comment":{"url":"https://api.github.com/repos/Zeex/pawn/issues/comments/216281266","html_url":"https://github.com/Zeex/pawn/issues/95#issuecomment-216281266","issue_url":"https://api.github.com/repos/Zeex/pawn/issues/95","id":216281266,"user":{"login":"Y-Less","id":991078,"avatar_url":"https://avatars.githubusercontent.com/u/991078?v=3","gravatar_id":"","url":"https://api.github.com/users/Y-Less","html_url":"https://github.com/Y-Less","followers_url":"https://api.github.com/users/Y-Less/followers","following_url":"https://api.github.com/users/Y-Less/following{/other_user}","gists_url":"https://api.github.com/users/Y-Less/gists{/gist_id}","starred_url":"https://api.github.com/users/Y-Less/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Y-Less/subscriptions","organizations_url":"https://api.github.com/users/Y-Less/orgs","repos_url":"https://api.github.com/users/Y-Less/repos","events_url":"https://api.github.com/users/Y-Less/events{/privacy}","received_events_url":"https://api.github.com/users/Y-Less/received_events","type":"User","site_admin":false},"created_at":"2016-05-02T16:17:59Z","updated_at":"2016-05-02T16:17:59Z","body":"Because of what I said about reassigning variables.  If someone writes a library like yours, uses the destructor feature, then allocates a variable twice, their old copy is lost.  Even in your code I'm not convinced it will work with your clever assignment operator:\r\n\r\n```pawn\r\nFunc()\r\n{\r\n    new List:a = List_Create();\r\n    new List:b = List_Create();\r\n    // We now have two lists - \"a\" and \"b\".\r\n    a = b;\r\n    // We now have three lists, the original one from \"a\",\r\n    // the original one from \"b\", and the new one in \"a\"\r\n    // created as a copy of \"b\" by your custom assignment operator.\r\n}\r\n```\r\n\r\nNow, when the scope ends, using the proposed destructor code, `a` and `b` will both go out of scope, and the destructor code will be run on the lists stored within them.  What happens to the original list from `a`?\r\n"}}