{"action":"created","issue":{"url":"https://api.github.com/repos/migueldeicaza/TensorFlowSharp/issues/104","repository_url":"https://api.github.com/repos/migueldeicaza/TensorFlowSharp","labels_url":"https://api.github.com/repos/migueldeicaza/TensorFlowSharp/issues/104/labels{/name}","comments_url":"https://api.github.com/repos/migueldeicaza/TensorFlowSharp/issues/104/comments","events_url":"https://api.github.com/repos/migueldeicaza/TensorFlowSharp/issues/104/events","html_url":"https://github.com/migueldeicaza/TensorFlowSharp/issues/104","id":245485239,"number":104,"title":"Fixed issue with memory-freeing callback delegates being garbage-collected in Windows.","user":{"login":"JohnTenney","id":5629942,"avatar_url":"https://avatars2.githubusercontent.com/u/5629942?v=4","gravatar_id":"","url":"https://api.github.com/users/JohnTenney","html_url":"https://github.com/JohnTenney","followers_url":"https://api.github.com/users/JohnTenney/followers","following_url":"https://api.github.com/users/JohnTenney/following{/other_user}","gists_url":"https://api.github.com/users/JohnTenney/gists{/gist_id}","starred_url":"https://api.github.com/users/JohnTenney/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/JohnTenney/subscriptions","organizations_url":"https://api.github.com/users/JohnTenney/orgs","repos_url":"https://api.github.com/users/JohnTenney/repos","events_url":"https://api.github.com/users/JohnTenney/events{/privacy}","received_events_url":"https://api.github.com/users/JohnTenney/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":5,"created_at":"2017-07-25T18:03:04Z","updated_at":"2017-07-29T02:28:59Z","closed_at":null,"body":"Frankly, not sure how to submit a pull request. So here's the info: on Windows, certain delegates that are used to free memory are being garbage collected, resulting in exceptions when trying to dispose TFTensor or TFBuffer classes. Attached are the fixes I made that resolved the issues.\r\n[TensorFlowSharp fixes.zip](https://github.com/migueldeicaza/TensorFlowSharp/files/1174316/TensorFlowSharp.fixes.zip)\r\n\r\nHad to make some minor changes, primarily to static constructors: Changed\r\n \r\nstatic TFBuffer ()\r\n              {\r\n                     FreeBufferFunc = Marshal.GetFunctionPointerForDelegate<BufferReleaseFunc> (FreeBlock);\r\n              }\r\n \r\nto\r\nstatic TFBuffer ()\r\n              {\r\n            BufferReleaseFunc del = (data, length) => FreeBlock(data, length);\r\n            GCHandle.Alloc(del);\r\n            FreeBufferFunc = Marshal.GetFunctionPointerForDelegate (del);\r\n              }\r\n \r\nAlso have to add the following code to TFTensor (and then replace use of FreeTensorHandle in the rest of the file with FreeTensorHandleFunc, and FreeTensorData with FreeTensorDataFunc):\r\n        static Deallocator FreeTensorHandleFunc;\r\n        static Deallocator FreeTensorDataFunc;\r\n        static TFTensor()\r\n        {\r\n            FreeTensorHandleFunc = (data, size, deallocatorData) => FreeTensorHandle(data, size, deallocatorData);\r\n            GCHandle.Alloc(FreeTensorHandleFunc);\r\n            FreeTensorDataFunc = (data, len, closure) => FreeTensorData(data, len, closure);\r\n            GCHandle.Alloc(FreeTensorDataFunc);\r\n        \r\n"},"comment":{"url":"https://api.github.com/repos/migueldeicaza/TensorFlowSharp/issues/comments/318797619","html_url":"https://github.com/migueldeicaza/TensorFlowSharp/issues/104#issuecomment-318797619","issue_url":"https://api.github.com/repos/migueldeicaza/TensorFlowSharp/issues/104","id":318797619,"user":{"login":"JohnTenney","id":5629942,"avatar_url":"https://avatars2.githubusercontent.com/u/5629942?v=4","gravatar_id":"","url":"https://api.github.com/users/JohnTenney","html_url":"https://github.com/JohnTenney","followers_url":"https://api.github.com/users/JohnTenney/followers","following_url":"https://api.github.com/users/JohnTenney/following{/other_user}","gists_url":"https://api.github.com/users/JohnTenney/gists{/gist_id}","starred_url":"https://api.github.com/users/JohnTenney/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/JohnTenney/subscriptions","organizations_url":"https://api.github.com/users/JohnTenney/orgs","repos_url":"https://api.github.com/users/JohnTenney/repos","events_url":"https://api.github.com/users/JohnTenney/events{/privacy}","received_events_url":"https://api.github.com/users/JohnTenney/received_events","type":"User","site_admin":false},"created_at":"2017-07-29T02:28:59Z","updated_at":"2017-07-29T02:28:59Z","body":"I too (eventually) figured out your fix. Think we're good.\n\nThanks!\n\nJohn\n\nOn Fri, Jul 28, 2017 at 4:58 PM, Miguel de Icaza <notifications@github.com>\nwrote:\n\n> I used two commits, one did the buffer, one did the tensor. I do not think\n> that Windows is optimizing that away, if the issue persists, can you share\n> what kind of error you are getting?\n>\n> I have Windows machine, I can test if you can share the program, and my\n> team tells me that this should also be debuggable on Linux with Mono, where\n> we have a debug flag to warn about these errors.MONO_DEBUG=keep-delegates\n> Would love to see what is happening.\n>\n> Very happy to hear that this binding has proved useful to you.\n>\n> —\n> You are receiving this because you authored the thread.\n> Reply to this email directly, view it on GitHub\n> <https://github.com/migueldeicaza/TensorFlowSharp/issues/104#issuecomment-318787106>,\n> or mute the thread\n> <https://github.com/notifications/unsubscribe-auth/AFXn9g2biW8DIgavfiUzismUy5aypUqIks5sSnWcgaJpZM4Oi6c4>\n> .\n>\n"}}
{"actor":{"display_login":"JohnTenney"}}