question

61877565 avatar image
0 Votes"
61877565 asked RoyLi-MSFT edited

How to allocate memory in C# for loop?

Hi ,

The question is that I try to create an instance to a variable in a loop and don't use this variable.
Like this :
9842-1.png

Then I use the 'Diagnostic Tool' in VS to track the memory in managed heap , however , I get only a count of Foo type in heap without GC behavior , it makes me very confuse. Hence , I infere that there is a optimization at run time for the variable which don't use in context and this optimization in order to save memory to only allocate one time in managed heap as no impact for application. I'm very very very thank you to give me some advice for that as this question let me can't keep good sleep every day.
9807-2.png


not-supported
1.png (66.7 KiB)
2.png (106.8 KiB)
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

1 Answer

DSPatrick avatar image
0 Votes"
DSPatrick answered

They're actively answering C# question in dedicated forums here.


https://social.msdn.microsoft.com/Forums/en-US/home?forum=csharpgeneral


--please don't forget to Accept as answer if the reply is helpful--


Regards, Dave Patrick ....
Microsoft Certified Professional
Microsoft MVP [Windows Server] Datacenter Management


Disclaimer: This posting is provided "AS IS" with no warranties or guarantees, and confers no rights.




5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.