I am using EF 4 and have the following code.
public static Dictionary<Tuple<int, string>, Country> CountryDict { get; set; }
public static Dictionary<int, State> StateDict { get; set; }
I ran memory profile and found that after filling these dictionaries, my ObjectContext doesnt get disposed because Country and State objects are still in the memory.
Am i using this incorrectly? Should i create a separate model class for Country and State and use them?
When you populate these collections, you can
Detachthese objects from their context, so the ObjectContext doesn’t try to track them anymore.Also, it’s usually best to create the ObjectContext in a
usingstatement, to ensure that it gets disposed in a timely manner.