Beef icon indicating copy to clipboard operation
Beef copied to clipboard

[Bug?] Some variations of LINQ calls result in leaks

Open marsej opened this issue 4 years ago • 1 comments

It's exciting to see LINQ available for Beef, there's been occasions I couldn't figure out how to do something without it!

The code below says there's 1 object memory leak. If Take(2) is removed, the memory leak warning goes away. Not sure how to fix this .. (0.43.0 win64,debug,default project settings in HelloWorld sample. Beef-linq-master from 2021 02 06)

using System.Linq;
...
			int[] test1 = scope .(10, 11, 10, 12, 13, 14, -1);
			int val = test1.Reverse().Where((x) => x > 0 && x % 2 == 0).Take(2).Sum();
			Console.WriteLine(val);

Same with this, except now if Reverse() is removed, the leak warning goes away :
			int[] test1 = scope .(10, 11, 10, 12, 13, 14, -1);
			var lst = test1.Reverse().Take(2);
			int val = lst.Sum();
			Console.WriteLine(val);

Same here, If Skip(2) is removed, the memory leak warning goes away.:
			int[] test1 = scope .(10, 11, 10, 12, 13, 14, -1);
			let lst = test1.Reverse().Skip(2);

This works:
			int[] test1 = scope .(10, 11, 10, 12, 13, 14, -1);
			var l = scope List<int>();
			test1.ToList(l);
			int val = l.Reverse().Sum();

Works:
			var x=scope int[](10, 11, 10, 12, 13, 14, -1);
			var ls = scope List<int>(x.GetEnumerator());
			int val = ls.Reverse().Sum();

Fails (leak):
			int[] test1 = scope .(10, 11, 10, 12, 13, 14, -1);
			var l = scope List<int>();
			test1.ToList(l);
			int val2 = l.Reverse().Take(2).Sum();

Works:
			int[] test1 = scope .(10, 11, 10, 12, 13, 14, -1);
			var l = scope List<int>();
			test1.ToList(l);
			var l2 = scope List<int>();
			l.Reverse().ToList(l2);
			var val2=l.Take(2).Sum();

Fails (leak):
			int[] test1 = scope .(10, 11, 10, 12, 13, 14, -1);
			var l = scope List<int>(test1.GetEnumerator());
			var l2 = scope List<int>(l.Reverse().GetEnumerator());
			var val2 = l2.Take(2).Sum();

Works:
			int[] test1 = scope .(10, 11, 10, 12, 13, 14, -1);
			var l = scope List<int>(test1.GetEnumerator());
			var l2 = scope List<int>();
			l.Reverse().ToList(l2);
			var val2 = l2.Take(2).Sum();

marsej avatar Apr 02 '21 10:04 marsej

@xposure

bfiete avatar Apr 02 '21 11:04 bfiete