線上訂房服務-台灣趴趴狗聯合訂房中心
發文 回覆 瀏覽次數:2920
推到 Plurk!
推到 Facebook!

threadvar釋放的問題

答題得分者是:syntax
rachex2000
一般會員


發表:21
回覆:32
積分:20
註冊:2003-04-28

發送簡訊給我
#1 引用回覆 回覆 發表時間:2005-08-15 14:20:24 IP:219.84.xxx.xxx 訂閱
根據Help的說法: Dynamic variables that are ordinarily managed by the compiler-long strings, wide strings, dynamic arrays, variants, and interfaces-can be declared with threadvar, but the compiler does not automatically free the heap-allocated memory created by each thread of execution. If you use these data types in thread variables, it is your responsibility to dispose of their memory. For example,    threadvar S: AnsiString;    S := 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';  ... S := '';  // free the memory used by S    那麼若宣告一    
type
  TRecord = record
    a: string;
    b: string;
    c: integer;
    ....... 
  end;    threadvar
  R, S, T: oRecord;
 
則Thread結束時,是否應釋放其用到的R, S, T等threadvar, 應如何寫?難道是將R, S, T的成員變數一一設為釋放嗎? 例如:
   R.a = '';
  R.b = '';
  ....
  S.a = '';
  S.b = '';
這樣Code不是很長嗎?有沒有簡便的寫法? 發表人 - rachex2000 於 2005/08/15 14:24:45
syntax
尊榮會員


發表:26
回覆:1139
積分:1258
註冊:2002-04-23

發送簡訊給我
#2 引用回覆 回覆 發表時間:2005-08-15 21:52:24 IP:61.64.xxx.xxx 未訂閱
R.a = ''; 這樣並無法釋放吧,只是將其值設為無 用 FreeMem,Disopse 或其他記憶體釋放函式
wameng
版主


發表:31
回覆:1336
積分:1188
註冊:2004-09-16

發送簡訊給我
#3 引用回覆 回覆 發表時間:2005-08-15 22:47:16 IP:219.86.xxx.xxx 未訂閱
finalize(..) ~~~~~~~~~~~ 難得聰明,常常糊塗。 ~~~~~~~~~~~
rachex2000
一般會員


發表:21
回覆:32
積分:20
註冊:2003-04-28

發送簡訊給我
#4 引用回覆 回覆 發表時間:2008-04-15 16:13:31 IP:203.66.xxx.xxx 訂閱
wameng的方法似乎可行,分數我好像給錯了,今天才發現,兩位不會介意吧!
系統時間:2024-04-25 6:15:05
聯絡我們 | Delphi K.Top討論版
本站聲明
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。
2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。
3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇!