【发布时间】:2012-03-25 19:05:46
【问题描述】:
我正在开发内存有限的 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,这不是浪费内存吗?在您的情况下,链接列表不会更有效,因为每个节点都是 BusStop。
标签: c# .net memory memory-management