I am developing C# application with limited memory. I initialize a large number of objects like the ones below which have several properties which takes up around 20MB. How can I reduce the amount of memory used by my application.
public class BusStop
{
private List<BusRoute> busRoutes = new List<BusRoute>();
private string name;
// ... Other properties omitted like Code, ID, Location, etc.
public BusStop(string name)
{
this.name = name;
}
public List<BusStop> BusRoutes
{
get { return this.busRoutes; }
}
public string Name
{
get { return this.name; }
}
}
public class BusRoute
{
private List<BusStop> busStops = new List<BusStop>();
private string name;
// ... Other properties omitted like Code, ID, Location, etc.
public BusStop(string name)
{
this.name = name;
}
public List<BusStop> BusStops
{
get { return this.busStops; }
}
public string Name
{
get { return this.name; }
}
}
Simple point – do not load them into memory. Wasteful and totally uinneeded. hey, when I order a supertanker full of oil to replace the oil in my car most of it is waste, what can i do – well, order only as much oil as you need, not a supertanker full.
Databases are there for a reason, you know.