Submitting on behalf of Metro style aps wih C++:Memory leaks with lambda expressionshttp://social.msdn.microsoft.com/Forums/en-US/winappswithnativecode/thread/52fb3b64-b5cd-4c1a-957e-a169384ae615Hello, I have the following code where I'm capturing a variable (test) which is an instance to a ref class.ThreadPool::RunAsync(ref new WorkItemHandler([test](Windows::Foundation::IAsyncAction^ operation) { ... }))->Start();C++ variables captured in this way are copied. I assume the instances of ref classes are just retained (using AddRef internally). The problem is that the instance isn't disposed when the lambda expression is destroyed. My understanding is that the instance of WorkItemHandler should be destroyed when the async operation is finished along with the lambda expression which should release all variables that are not captured by reference.Is this a bug in the preview version of the compiler or am I doing something wrong?Monday, October 31, 2011 9:13 PM Ben Kuhn [MSFT]MicrosoftYour expectations are correct, but we can't reproduce the behavior you are seeing with just the minimal snippet above. Can you provide a complete, minimal repro? What are you observing that leads you to believe there's a missing release call? I ask because it's also possible that some other component wiring is broken, instead. Thanks, Ben KuhnMonday, October 31, 2011 10:25 PM AtamiriHi Ben, thank you for looking at my problem. In the code below the destructor of Test isn't called. It's called if I use [&] instead of [=]. ref class Test {public: ~Test() { OutputDebugStringW(L"Disposed\n"); } void Dummy() { OutputDebugStringW(L"Dummy\n"); }};delegate void MyDelegate();[Platform::MTAThread]int main(array<Platform::String^>^) { { auto test = ref new Test(); auto lmbd = [=](){ test->Dummy(); }; auto dlgt = ref new MyDelegate(lmbd); } OutputDebugStringW(L"End\n");}Wednesday, November 02, 2011 4:59 PM Ben Kuhn [MSFT]MicrosoftPossibly. I've sent this over to the compiler team to have someone take a look. I'll post back here as soon as I get a response. Thanks, Ben Kuhn
Visual Studio/Team Foundation Server/.NET Framework Tooling version
Steps to reproduce
Product Language
Operating System
Operating System Language
Actual results
Expected results