Can this object be stored in ViewState and Garbage Collected

Last post 10-16-2008 12:48 AM by dotnetorbust. 0 replies.

Sort Posts:

  • Can this object be stored in ViewState and Garbage Collected

    10-16-2008, 12:48 AM
    • Member
      29 point Member
    • dotnetorbust
    • Member since 05-14-2003, 9:34 AM
    • Posts 19

    If you had a class like the one below, is it safe to store this in viewstate?

    Also, I've read that the GC sometimes has a problem clearing collections.

    Is there any way to make sure that doesn't happen (or just "object = null;") :

    thanks

    using System;

    using System.Configuration;

    using System.Linq;

    using System.Web;

    using System.Xml.Linq;

    using System.Collections.Generic;

     

    namespace Sample

    {

    [
    Serializable]

    public class Preferences

    {

    private List<Preference> currentPreferences;public Preferences()

    {

    Initialize();

    }

    private void Initialize()

    {

    EmailAddress =
    String.Empty;

    Type = String.Empty;

    TimeStamp = Convert.ToDateTime("1/1/1900");currentPreferences = new List<Preference>();

    }

    public string EmailAddress {get;set;}

    public string Type {get;set;}

    public DateTime TimeStamp {get;set;}

    public List<Preference> CurrentPreferences

    {

    get { return currentPreferences; }set { currentPreferences = value; }

    }

    public void AddPreference(string _id, string _setting)

    {

    currentPreferences.Add(
    new Sample.Preference(_id, _setting));

    }

    }

    [
    Serializable]

    public class Preference

    {

    public Preference()

    {

    Initialize();

    }

    public Preference(string _id, string _setting)

    {

    Initialize();

    Id = _id;

    Setting = _setting;

    }

    private void Initialize()

    {

    Id =
    String.Empty;Setting = String.Empty;

    }

    public string Id {get;set;}

    public string Setting {get;set;}

    }

    }

Page 1 of 1 (1 items)