Bug 14077 - HashSet capacity increases on every deserialization
Summary: HashSet capacity increases on every deserialization
Alias: None
Product: Class Libraries
Classification: Mono
Component: System.Core ()
Version: master
Hardware: Other Linux
: --- normal
Target Milestone: Untriaged
Assignee: Bugzilla
Depends on:
Reported: 2013-08-19 14:16 UTC by David Straw
Modified: 2013-08-21 00:15 UTC (History)
2 users (show)

Is this bug a regression?: ---
Last known good build:

Simple program to reproduce the issue (1.02 KB, text/plain)
2013-08-19 14:18 UTC, David Straw

Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.

Please create a new report on GitHub or Developer Community with your current version information, steps to reproduce, and relevant error messages or log files if you are hitting an issue that looks similar to this resolved bug and you do not yet see a matching new report.

Related Links:

Description David Straw 2013-08-19 14:16:03 UTC
Description of Problem:
The length of the table used to store values in HashSet increases during deserialization. I found that every serialize/deserialize cycle increases the size of the table by around 2.5 times. After a dozen or so times of doing this, the application typically runs out of memory.

Steps to reproduce the problem:
1. Iteratively serialize and deserialize a HashSet with a few items in it
2. Observe the length of the 'table' private field

Actual Results:
The length of the table field (and therefore the memory it uses) increases significantly on each serialize/deserialize iteration.

Expected Results:
The table should not keep increasing in size.

How often does this happen? 
100% of the time the HashSet is deserialized with any items in it.

Additional Information:
It looks like not all of the fields are being initialized properly on deserialization, in particular 'threshold' and 'links'.

I'll work on a test case and a pull request.
Comment 1 David Straw 2013-08-19 14:18:40 UTC
Created attachment 4661 [details]
Simple program to reproduce the issue
Comment 2 David Straw 2013-08-19 15:52:03 UTC
Created a pull request:
Comment 3 Miguel de Icaza [MSFT] 2013-08-21 00:15:14 UTC
Pull request was accepted.