小编DaM*_*chk的帖子

C#minmax图搜索

编辑3:好的,所以我让我的代码工作,但如果我使用16个节点并且搜索深度大于11,我将面临巨大的内存消耗问题.

一个soemone检查代码并告诉我如何纠正内存泄漏?

这是完整的代码:

public void searchTSP(
    int depth,
    RouterPoint startpoint,
    bool isRound,
    IRouter<RouterPoint> router)
{
  #region TSP_startpointCheck
  if (!routepoints[0].Location.Equals(startpoint.Location))
  {
    int index = Array
      .FindIndex(routepoints, x => x.Location == startpoint.Location);

    if (index != -1 && index != 0) //it's somewhere in the array
    {
      RouterPoint temprp = routepoints[0];
      routepoints[0] = routepoints[index]; //put it to index 0
      routepoints[index] = temprp;
    }
    else //it's not in the array
    {
      //we add it...
      RouterPoint[] ta = new RouterPoint[routepoints.Length + 1];
      routepoints.CopyTo(ta, 0);
      ta[routepoints.Length] …
Run Code Online (Sandbox Code Playgroud)

c# memory-leaks traveling-salesman tree-traversal graph-traversal

6
推荐指数
1
解决办法
554
查看次数