views:

6

answers:

0

I have an example piece of code the illustrates issues in my code when GC.Collect is carried out on a class having a ReaderWriterLockSlim member variable. The GC.Collect takes between 2 and 3 seconds to run. I need to carry out GC at regular intervals because my applicaton is extremely memory intensive.

namespace WpfApplication12
{
    public class DataItem
    {
        private readonly ReaderWriterLockSlim m_propertyLock = new ReaderWriterLockSlim();

        public DataItem()
        {
        }
    }

    /// <summary>
    /// Interaction logic for Window1.xaml
    /// </summary>
    public partial class Window1 : Window
    {
        public Window1()
        {
            InitializeComponent();

            List<DataItem> dataItemList = new List<DataItem>();
            for (int i = 0; i < 100000; i++)
            {
                dataItemList.Add(new DataItem());
            }

            Debug.WriteLine(DateTime.Now.ToString());
            GC.Collect();
            Debug.WriteLine(DateTime.Now.ToString());
        }
    }
}

Has anyone had similar problems?

Thanks Ian