Moin zusammen,
ich würde gerne mal eure Meinung zu folgender Problemstellung wissen:
Also meiner Meinung nach ist das (jetzt nicht gerade sinnvoller aber) valider C# Code. Jedoch bleibt das Array für immer stehen, also eigentlich ein Leck, obwohl ich nach dem entfernen der Action aus der Liste keine Referenzen mehr darauf habe. Ist das ein Leck im System oder habe ich da was übersehen?
ich würde gerne mal eure Meinung zu folgender Problemstellung wissen:
C#-Quellcode
- namespace ConsoleApp1 {
- class Program {
- static void Main(string[] args) {
- List<Action> actions = new List<Action>();
- Task.Run(() => {
- byte[] data = new byte[100_000_000];
- for (int i = 0; i < data.Length; i++) {
- data[i] = 1;
- }
- actions.Add(() => {
- data[44] = 22;
- });
- });
- while (true) {
- System.Threading.Thread.Sleep(2000);
- if (actions.Count > 0) {
- actions[0]();
- actions.RemoveAt(0);
- Console.WriteLine("Action done!");
- }
- GC.Collect();
- GC.WaitForPendingFinalizers();
- GC.Collect();
- }
- }
- }
- }
Also meiner Meinung nach ist das (jetzt nicht gerade sinnvoller aber) valider C# Code. Jedoch bleibt das Array für immer stehen, also eigentlich ein Leck, obwohl ich nach dem entfernen der Action aus der Liste keine Referenzen mehr darauf habe. Ist das ein Leck im System oder habe ich da was übersehen?