[MSV8i C#] 内存释放问题

各位老师好,

      我在调用CreateSharedCellElement2方法后,发现内存增加,因为要重复调用很多次,所以就出现了程序崩溃的问题。

      我想问下如何释放这部分内存?

Parents
  • C#里边Manged类型的实例不需要程序员去负责内存释放的问题。程序崩溃可能是别的原因,请上传一下您的代码,我帮您分析一下。

  •             Matrix3d xMatrix = app.Matrix3dFromAxisAndRotationAngle(2, xRadians);
                Matrix3d zMatrix = app.Matrix3dFromAxisAndRotationAngle(0, -zRadians); 
                Matrix3d yMatrix = app.Matrix3dFromAxisAndRotationAngle(1, yRadians);
    
                Point3d scale3d = app.Point3dFromXYZ(scale, scale, scale);
    
                SharedCellElement cell = null;
    
                try
                {
                   
                    Matrix3d rMatrix = app.Matrix3dFromMatrix3dTimesMatrix3dTimesMatrix3d(ref xMatrix, ref yMatrix, ref zMatrix);
                    
                    cell = app.CreateSharedCellElement2(name, ref ptOnAlignment, ref scale3d, true, ref rMatrix);
                    if (cell != null)
                    {  
                        cell.Color = color;
                        cell.Level = level;
                        app.ActiveModelReference.AddElement(cell);    
                    } 
                }
                catch (InvalidCastException ex)
                {
                    Console.Write(ex.Message);
                }
                       
                return cell;

    老师,您好,我每次跟踪代码,发现执行“cell = app.CreateSharedCellElement2(name, ref ptOnAlignment, ref scale3d, true, ref rMatrix);”这句内存就增长

  • 取消最后一行这个return cell试一下。已经AddElement添加到模型中了还要返回这个cell的目的是什么?

    在AddElement后增加cell=null;看能否及时清除内存。



Reply Children