In a WinRT component project, I have an async operation which takes an array as an argument. Although captured, the array seems to have been deallocated when the worker lambda gets to touch it.static IAsyncOperation<int>^ SumNumbers(const Array<int>^ numbers){ return create_async([numbers] ()->int { int sum = 0; for(unsigned int i=0; i<numbers->Length; ++i) sum += numbers[i]; return sum; });}This causes an access violation when 'numbers' is referenced within the lambda, and debugging printout does show that the variable is indeed garbage.Changing it to create a copy of the input array, as in:static IAsyncOperation<int>^ SumNumbers(const Array<int>^ numbers){ auto numbers2 = ref new Array<int>(numbers); return create_async([numbers2] ()->int { int sum = 0; for(unsigned int i=0; i<numbers2->Length; ++i) sum += numbers2[i]; return sum; });}does work, but with an extra copy of course.Should capturing 'numbers' in the lambda environment increment the reference count to keep the variable alive for the lambda to process?
Visual Studio/Team Foundation Server/.NET Framework Tooling Version
Steps to reproduce
Product Language
Operating System
Operating System Language
Actual results
Expected results