{"action":"created","comment":{"url":"https://api.github.com/repos/mono/CppSharp/pulls/comments/46710136","id":46710136,"diff_hunk":"@@ -1273,10 +1273,51 @@ public void GenerateVTable(Class @class)\n \n             GenerateVTableClassSetup(@class, wrappedEntries);\n \n+            GenerateVTableCleanup(@class, wrappedEntries);\n+\n             WriteLine(\"#endregion\");\n             PopBlock(NewLineKind.BeforeNextBlock);\n         }\n \n+        private void GenerateVTableCleanup(Class @class, IList<VTableComponent> wrappedEntries)\n+        {\n+            WriteLine(\"private static readonly Destructor Finalise = new Destructor();\");\n+            WriteLine(\"private sealed class Destructor\");\n+            WriteStartBraceIndent();\n+            WriteLine(\"~Destructor()\");\n+            WriteStartBraceIndent();\n+            WriteLine(\"if (__ManagedVTables != null)\");\n+            WriteStartBraceIndent();\n+            DeAllocateVTables(@class, wrappedEntries, false);\n+            WriteCloseBraceIndent();\n+            WriteCloseBraceIndent();\n+            WriteCloseBraceIndent();\n+        }\n+\n+        private void DeAllocateVTables(Class @class, IList<VTableComponent> wrappedEntries,\n+            bool destructorOnly)\n+        {\n+            if (Options.IsMicrosoftAbi)\n+                DeAllocateVTablesMS(@class, wrappedEntries, destructorOnly);\n+            else\n+                DeAllocateVTablesItanium(@class, wrappedEntries, destructorOnly);\n+        }\n+\n+        private void DeAllocateVTablesMS(Class @class, IList<VTableComponent> wrappedEntries,\n+            bool destructorOnly)\n+        {\n+            var managedVTables = destructorOnly ? \"__ManagedVTablesDtorOnly\" : \"__ManagedVTables\";\n+            for (int tableIndex = 0; tableIndex < @class.Layout.VFTables.Count; tableIndex++)\n+                WriteLine(\"Marshal.FreeHGlobal((System.IntPtr){0}[{1}]);\", managedVTables, tableIndex);\n+        }\n+\n+        private void DeAllocateVTablesItanium(Class @class, IList<VTableComponent> wrappedEntries,\n+            bool destructorOnly)\n+        {\n+            var managedVTables = destructorOnly ? \"__ManagedVTablesDtorOnly\" : \"__ManagedVTables\";","path":"src/Generator/Generators/CSharp/CSharpTextTemplate.cs","position":45,"original_position":45,"commit_id":"156b80096d0b51de8e67e26ab8822a85710cdb34","original_commit_id":"156b80096d0b51de8e67e26ab8822a85710cdb34","user":{"login":"ddobrev","id":5193072,"avatar_url":"https://avatars.githubusercontent.com/u/5193072?v=3","gravatar_id":"","url":"https://api.github.com/users/ddobrev","html_url":"https://github.com/ddobrev","followers_url":"https://api.github.com/users/ddobrev/followers","following_url":"https://api.github.com/users/ddobrev/following{/other_user}","gists_url":"https://api.github.com/users/ddobrev/gists{/gist_id}","starred_url":"https://api.github.com/users/ddobrev/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ddobrev/subscriptions","organizations_url":"https://api.github.com/users/ddobrev/orgs","repos_url":"https://api.github.com/users/ddobrev/repos","events_url":"https://api.github.com/users/ddobrev/events{/privacy}","received_events_url":"https://api.github.com/users/ddobrev/received_events","type":"User","site_admin":false},"body":"Same as the MS case.","created_at":"2015-12-04T17:51:22Z","updated_at":"2015-12-04T17:51:22Z","html_url":"https://github.com/mono/CppSharp/pull/592#discussion_r46710136","pull_request_url":"https://api.github.com/repos/mono/CppSharp/pulls/592","_links":{"self":{"href":"https://api.github.com/repos/mono/CppSharp/pulls/comments/46710136"},"html":{"href":"https://github.com/mono/CppSharp/pull/592#discussion_r46710136"},"pull_request":{"href":"https://api.github.com/repos/mono/CppSharp/pulls/592"}}},"pull_request":{"url":"https://api.github.com/repos/mono/CppSharp/pulls/592","id":52696691,"html_url":"https://github.com/mono/CppSharp/pull/592","diff_url":"https://github.com/mono/CppSharp/pull/592.diff","patch_url":"https://github.com/mono/CppSharp/pull/592.patch","issue_url":"https://api.github.com/repos/mono/CppSharp/issues/592","number":592,"state":"open","locked":false,"title":"Initial patch to free allocated VTables.","user":{"login":"genuinelucifer","id":11402325,"avatar_url":"https://avatars.githubusercontent.com/u/11402325?v=3","gravatar_id":"","url":"https://api.github.com/users/genuinelucifer","html_url":"https://github.com/genuinelucifer","followers_url":"https://api.github.com/users/genuinelucifer/followers","following_url":"https://api.github.com/users/genuinelucifer/following{/other_user}","gists_url":"https://api.github.com/users/genuinelucifer/gists{/gist_id}","starred_url":"https://api.github.com/users/genuinelucifer/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/genuinelucifer/subscriptions","organizations_url":"https://api.github.com/users/genuinelucifer/orgs","repos_url":"https://api.github.com/users/genuinelucifer/repos","events_url":"https://api.github.com/users/genuinelucifer/events{/privacy}","received_events_url":"https://api.github.com/users/genuinelucifer/received_events","type":"User","site_admin":false},"body":"I have simply done the FreeHGlobal call for each AllocHGlobal in ```SetupVTables()```\r\n.\r\nI have yet to test it.","created_at":"2015-12-04T17:21:59Z","updated_at":"2015-12-04T17:51:22Z","closed_at":null,"merged_at":null,"merge_commit_sha":"0551bee33985f23c0ccab65f331d08d61f0d0fd0","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/mono/CppSharp/pulls/592/commits","review_comments_url":"https://api.github.com/repos/mono/CppSharp/pulls/592/comments","review_comment_url":"https://api.github.com/repos/mono/CppSharp/pulls/comments{/number}","comments_url":"https://api.github.com/repos/mono/CppSharp/issues/592/comments","statuses_url":"https://api.github.com/repos/mono/CppSharp/statuses/156b80096d0b51de8e67e26ab8822a85710cdb34","head":{"label":"genuinelucifer:clean_vtables","ref":"clean_vtables","sha":"156b80096d0b51de8e67e26ab8822a85710cdb34","user":{"login":"genuinelucifer","id":11402325,"avatar_url":"https://avatars.githubusercontent.com/u/11402325?v=3","gravatar_id":"","url":"https://api.github.com/users/genuinelucifer","html_url":"https://github.com/genuinelucifer","followers_url":"https://api.github.com/users/genuinelucifer/followers","following_url":"https://api.github.com/users/genuinelucifer/following{/other_user}","gists_url":"https://api.github.com/users/genuinelucifer/gists{/gist_id}","starred_url":"https://api.github.com/users/genuinelucifer/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/genuinelucifer/subscriptions","organizations_url":"https://api.github.com/users/genuinelucifer/orgs","repos_url":"https://api.github.com/users/genuinelucifer/repos","events_url":"https://api.github.com/users/genuinelucifer/events{/privacy}","received_events_url":"https://api.github.com/users/genuinelucifer/received_events","type":"User","site_admin":false},"repo":{"id":35488262,"name":"CppSharp","full_name":"genuinelucifer/CppSharp","owner":{"login":"genuinelucifer","id":11402325,"avatar_url":"https://avatars.githubusercontent.com/u/11402325?v=3","gravatar_id":"","url":"https://api.github.com/users/genuinelucifer","html_url":"https://github.com/genuinelucifer","followers_url":"https://api.github.com/users/genuinelucifer/followers","following_url":"https://api.github.com/users/genuinelucifer/following{/other_user}","gists_url":"https://api.github.com/users/genuinelucifer/gists{/gist_id}","starred_url":"https://api.github.com/users/genuinelucifer/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/genuinelucifer/subscriptions","organizations_url":"https://api.github.com/users/genuinelucifer/orgs","repos_url":"https://api.github.com/users/genuinelucifer/repos","events_url":"https://api.github.com/users/genuinelucifer/events{/privacy}","received_events_url":"https://api.github.com/users/genuinelucifer/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/genuinelucifer/CppSharp","description":"Tools to surface C++ APIs to C#","fork":true,"url":"https://api.github.com/repos/genuinelucifer/CppSharp","forks_url":"https://api.github.com/repos/genuinelucifer/CppSharp/forks","keys_url":"https://api.github.com/repos/genuinelucifer/CppSharp/keys{/key_id}","collaborators_url":"https://api.github.com/repos/genuinelucifer/CppSharp/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/genuinelucifer/CppSharp/teams","hooks_url":"https://api.github.com/repos/genuinelucifer/CppSharp/hooks","issue_events_url":"https://api.github.com/repos/genuinelucifer/CppSharp/issues/events{/number}","events_url":"https://api.github.com/repos/genuinelucifer/CppSharp/events","assignees_url":"https://api.github.com/repos/genuinelucifer/CppSharp/assignees{/user}","branches_url":"https://api.github.com/repos/genuinelucifer/CppSharp/branches{/branch}","tags_url":"https://api.github.com/repos/genuinelucifer/CppSharp/tags","blobs_url":"https://api.github.com/repos/genuinelucifer/CppSharp/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/genuinelucifer/CppSharp/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/genuinelucifer/CppSharp/git/refs{/sha}","trees_url":"https://api.github.com/repos/genuinelucifer/CppSharp/git/trees{/sha}","statuses_url":"https://api.github.com/repos/genuinelucifer/CppSharp/statuses/{sha}","languages_url":"https://api.github.com/repos/genuinelucifer/CppSharp/languages","stargazers_url":"https://api.github.com/repos/genuinelucifer/CppSharp/stargazers","contributors_url":"https://api.github.com/repos/genuinelucifer/CppSharp/contributors","subscribers_url":"https://api.github.com/repos/genuinelucifer/CppSharp/subscribers","subscription_url":"https://api.github.com/repos/genuinelucifer/CppSharp/subscription","commits_url":"https://api.github.com/repos/genuinelucifer/CppSharp/commits{/sha}","git_commits_url":"https://api.github.com/repos/genuinelucifer/CppSharp/git/commits{/sha}","comments_url":"https://api.github.com/repos/genuinelucifer/CppSharp/comments{/number}","issue_comment_url":"https://api.github.com/repos/genuinelucifer/CppSharp/issues/comments{/number}","contents_url":"https://api.github.com/repos/genuinelucifer/CppSharp/contents/{+path}","compare_url":"https://api.github.com/repos/genuinelucifer/CppSharp/compare/{base}...{head}","merges_url":"https://api.github.com/repos/genuinelucifer/CppSharp/merges","archive_url":"https://api.github.com/repos/genuinelucifer/CppSharp/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/genuinelucifer/CppSharp/downloads","issues_url":"https://api.github.com/repos/genuinelucifer/CppSharp/issues{/number}","pulls_url":"https://api.github.com/repos/genuinelucifer/CppSharp/pulls{/number}","milestones_url":"https://api.github.com/repos/genuinelucifer/CppSharp/milestones{/number}","notifications_url":"https://api.github.com/repos/genuinelucifer/CppSharp/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/genuinelucifer/CppSharp/labels{/name}","releases_url":"https://api.github.com/repos/genuinelucifer/CppSharp/releases{/id}","created_at":"2015-05-12T13:05:40Z","updated_at":"2015-05-12T13:05:41Z","pushed_at":"2015-12-04T16:53:21Z","git_url":"git://github.com/genuinelucifer/CppSharp.git","ssh_url":"git@github.com:genuinelucifer/CppSharp.git","clone_url":"https://github.com/genuinelucifer/CppSharp.git","svn_url":"https://github.com/genuinelucifer/CppSharp","homepage":null,"size":16183,"stargazers_count":0,"watchers_count":0,"language":"C#","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"mono:master","ref":"master","sha":"91e7625b3090bae43be85f2e7819c6cf7fc2bd20","user":{"login":"mono","id":53395,"avatar_url":"https://avatars.githubusercontent.com/u/53395?v=3","gravatar_id":"","url":"https://api.github.com/users/mono","html_url":"https://github.com/mono","followers_url":"https://api.github.com/users/mono/followers","following_url":"https://api.github.com/users/mono/following{/other_user}","gists_url":"https://api.github.com/users/mono/gists{/gist_id}","starred_url":"https://api.github.com/users/mono/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mono/subscriptions","organizations_url":"https://api.github.com/users/mono/orgs","repos_url":"https://api.github.com/users/mono/repos","events_url":"https://api.github.com/users/mono/events{/privacy}","received_events_url":"https://api.github.com/users/mono/received_events","type":"Organization","site_admin":false},"repo":{"id":9988318,"name":"CppSharp","full_name":"mono/CppSharp","owner":{"login":"mono","id":53395,"avatar_url":"https://avatars.githubusercontent.com/u/53395?v=3","gravatar_id":"","url":"https://api.github.com/users/mono","html_url":"https://github.com/mono","followers_url":"https://api.github.com/users/mono/followers","following_url":"https://api.github.com/users/mono/following{/other_user}","gists_url":"https://api.github.com/users/mono/gists{/gist_id}","starred_url":"https://api.github.com/users/mono/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mono/subscriptions","organizations_url":"https://api.github.com/users/mono/orgs","repos_url":"https://api.github.com/users/mono/repos","events_url":"https://api.github.com/users/mono/events{/privacy}","received_events_url":"https://api.github.com/users/mono/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/mono/CppSharp","description":"Tools to surface C++ APIs to C#","fork":false,"url":"https://api.github.com/repos/mono/CppSharp","forks_url":"https://api.github.com/repos/mono/CppSharp/forks","keys_url":"https://api.github.com/repos/mono/CppSharp/keys{/key_id}","collaborators_url":"https://api.github.com/repos/mono/CppSharp/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/mono/CppSharp/teams","hooks_url":"https://api.github.com/repos/mono/CppSharp/hooks","issue_events_url":"https://api.github.com/repos/mono/CppSharp/issues/events{/number}","events_url":"https://api.github.com/repos/mono/CppSharp/events","assignees_url":"https://api.github.com/repos/mono/CppSharp/assignees{/user}","branches_url":"https://api.github.com/repos/mono/CppSharp/branches{/branch}","tags_url":"https://api.github.com/repos/mono/CppSharp/tags","blobs_url":"https://api.github.com/repos/mono/CppSharp/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/mono/CppSharp/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/mono/CppSharp/git/refs{/sha}","trees_url":"https://api.github.com/repos/mono/CppSharp/git/trees{/sha}","statuses_url":"https://api.github.com/repos/mono/CppSharp/statuses/{sha}","languages_url":"https://api.github.com/repos/mono/CppSharp/languages","stargazers_url":"https://api.github.com/repos/mono/CppSharp/stargazers","contributors_url":"https://api.github.com/repos/mono/CppSharp/contributors","subscribers_url":"https://api.github.com/repos/mono/CppSharp/subscribers","subscription_url":"https://api.github.com/repos/mono/CppSharp/subscription","commits_url":"https://api.github.com/repos/mono/CppSharp/commits{/sha}","git_commits_url":"https://api.github.com/repos/mono/CppSharp/git/commits{/sha}","comments_url":"https://api.github.com/repos/mono/CppSharp/comments{/number}","issue_comment_url":"https://api.github.com/repos/mono/CppSharp/issues/comments{/number}","contents_url":"https://api.github.com/repos/mono/CppSharp/contents/{+path}","compare_url":"https://api.github.com/repos/mono/CppSharp/compare/{base}...{head}","merges_url":"https://api.github.com/repos/mono/CppSharp/merges","archive_url":"https://api.github.com/repos/mono/CppSharp/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/mono/CppSharp/downloads","issues_url":"https://api.github.com/repos/mono/CppSharp/issues{/number}","pulls_url":"https://api.github.com/repos/mono/CppSharp/pulls{/number}","milestones_url":"https://api.github.com/repos/mono/CppSharp/milestones{/number}","notifications_url":"https://api.github.com/repos/mono/CppSharp/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/mono/CppSharp/labels{/name}","releases_url":"https://api.github.com/repos/mono/CppSharp/releases{/id}","created_at":"2013-05-10T19:00:56Z","updated_at":"2015-11-30T05:15:50Z","pushed_at":"2015-12-04T17:22:00Z","git_url":"git://github.com/mono/CppSharp.git","ssh_url":"git@github.com:mono/CppSharp.git","clone_url":"https://github.com/mono/CppSharp.git","svn_url":"https://github.com/mono/CppSharp","homepage":null,"size":21135,"stargazers_count":375,"watchers_count":375,"language":"C#","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":92,"mirror_url":null,"open_issues_count":67,"forks":92,"open_issues":67,"watchers":375,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/mono/CppSharp/pulls/592"},"html":{"href":"https://github.com/mono/CppSharp/pull/592"},"issue":{"href":"https://api.github.com/repos/mono/CppSharp/issues/592"},"comments":{"href":"https://api.github.com/repos/mono/CppSharp/issues/592/comments"},"review_comments":{"href":"https://api.github.com/repos/mono/CppSharp/pulls/592/comments"},"review_comment":{"href":"https://api.github.com/repos/mono/CppSharp/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/mono/CppSharp/pulls/592/commits"},"statuses":{"href":"https://api.github.com/repos/mono/CppSharp/statuses/156b80096d0b51de8e67e26ab8822a85710cdb34"}}}}