Here is a little test that reproduces the problem. I thought that initializing the memory stream to a size bigger than the entire list would fix the problem but it only makes it happen less quickly in some cases. If you play with the numbers in my little test to reduce the size of allocated memory, you will notice that it takes longer to run out of memory but it still happens after a while. The way it behaves, it really looks like a leak since I have a loop that does the same thing at every run and I would expect the memory allocator to be able to reuse the same memory instead of growing the heap. Note that I compiled the test with VS 2005. I don't know if I could reproduce the bug using the mono compiler. Jonathan
_____ De : [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] De la part de Alan McGovern Envoyé : Thursday, May 10, 2007 11:45 AM À : Mono-list@lists.ximian.com Objet : [Mono-list] Too many heap sections: Increase MAXHINCRorMAX_HEAP_SECTS >Also, as a test, could you initialise the memory stream to roughly the size required to store the entire list<T> and see if it works then. That works fine if I do it that way. But my problem is that I can't really know in advance how much memory the serialization will use, so it's not really a viable solution. I'm thinking of trying to split up my list into smaller chunks to see it this could fix the problem by avoiding the large object heap, if there is such a heap in mono. Sounds like your problem is due to heap fragmentation. The only solution is to use a best-guess for the approximate size of the memory stream and initialise the memorystream to that to start off with. For example if the average size of your class is 68 bytes, then initialise the memorystream to array.Length * 68. Or some such thing. Still, a testcase may prove useful. Alan.
using System; using System.Collections.Generic; using System.Text; using System.IO; using System.Runtime.Serialization.Formatters.Binary; namespace TestApp { class Program { static void Main(string[] args) { BinaryFormatter binaryFormatter = new BinaryFormatter(); List<object[]> list; object[] objectArray = null; while (true) { list = new List<object[]>(); int num = 13500; for (int j = 0; j < num; ++j) { objectArray = new object[100]; for (int i = 0; i < objectArray.Length; ++i) { int modulo = i % 4; switch (modulo) { case 0: objectArray[i] = new String(new char[] { 'A', 'B', 'C' }); break; case 1: objectArray[i] = new Int32(); break; case 2: objectArray[i] = new Boolean(); break; case 3: objectArray[i] = Guid.NewGuid(); break; } } list.Add(objectArray); } MemoryStream memoryStream = new MemoryStream(17000000); binaryFormatter.Serialize(memoryStream, list); Console.WriteLine(memoryStream.Length); } } } }
_______________________________________________ Mono-list maillist - Mono-list@lists.ximian.com http://lists.ximian.com/mailman/listinfo/mono-list