我正在開發限制內存的C#應用程序。我初始化了大量的對象,如下面那些有幾個屬性的對象,大約需要20MB。如何減少我的應用程序使用的內存量。減少我的應用程序的內存佔用量
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; }
}
}
我不禁注意到你存儲BusRoute的每一站和巴士站就爲每一個路線,不是嗎」那是浪費內存?因爲每個節點都是BusStop,所以你的情況不會更有效。 – alykhalid 2012-03-08 09:32:47