我在程序中动态的创建了一个对象,在我不想用它时我要把他释放掉,但我发现无论我用Destroy还是
free方法整个程序站用得内存没有减少啊,为什么?到底怎么样做我才能释放掉他所占用的内存?

解决方案 »

  1.   

    该用 对象 := nil 试试
      

  2.   

    那你主动要求操作系统释放
    uses PsAPI;使用 EmptyWorkingSet
      

  3.   

    EmptyWorkingSet怎么用啊?多谢!
      

  4.   

    EmptyWorkingSet(GetCurrentProcess)或者SetProcessWorkingSetSize(-1,-1)
      

  5.   

    EmptyWorkingSet(GetCurrentProcess)
    俺就知道一个  
      

  6.   

    Create时,你是声明了这块内存是我的,别人不准用,并初始化。
    同样Free时,你只是声明了这块内存我不用了,剩下的系统会作,并不会立刻放掉。
    当有别的程序要用这块内存的时候系统会将这块不用的内存划给它(有算法的,看看操作系统方面的书)。
      

  7.   

    GetCurrentProcess返回得是什么东西?
      

  8.   

    delphi 的 NEW 和  FREE 是由delphi 的运行库管理,而不是直接由操作系统管理
      

  9.   

    GetCurrentProcess返回当前进程Hprocess句柄2000以上系统用EmptyWorkingSet强制释放没被使用的内存页面The EmptyWorkingSet function removes as many pages as possible from the working set of the specified process.
    BOOL EmptyWorkingSet(
      HANDLE hProcess
    );Parameters
    hProcess 
    [in] Handle to the process. The handle must have the PROCESS_QUERY_INFORMATION and PROCESS_SET_INFORMATION access rights. For more information, see Process Security and Access Rights. 
    Return Values
    If the function succeeds, the return value is nonzero.If the function fails, the return value is zero. To get extended error information, call GetLastError.Res
    You can also use the SetProcessWorkingSetSize function to do what EmptyWorkingSet does if you pass it -1 for the minimum and maximum sizes.Requirements
    Client: Requires Windows XP, Windows 2000 Professional, or Windows NT Workstation 4.0.
    Server: Requires Windows Server 2003, Windows 2000 Server, or Windows NT Server 4.0.
    Header: Declared in Psapi.h.
    Library: Use Psapi.lib.