找回密码
 点一下
查看: 1799|回复: 6

还是关于 排泄 的问题

[复制链接]
发表于 2008-2-25 21:34:17 | 显示全部楼层 |阅读模式
[codes=jass]function YouGuanPaiXie_Actions takes nothing returns nothing
    call QuestMessageBJ( GetPlayersAll(), bj_QUESTMESSAGE_UPDATED, "学习JASS" )
endfunction

function YouGuanPaiXie takes nothing returns nothing
    local trigger trig = CreateTrigger(  )
    local triggeraction trigact = TriggerAddAction( trig, function YouGuanPaiXie_Actions )
    call TriggerRegisterTimerEventSingle( trig, 2.00 )
    set trig = null
    set trigact = null
endfunction
//这样就可以没有泄漏了吧

function Trig_YouGuanPaiXie_Actions takes nothing returns nothing
    call QuestMessageBJ( GetPlayersAll(), bj_QUESTMESSAGE_UPDATED, "学习JASS" )
endfunction

//===========================================================================
function InitTrig_YouGuanPaiXie takes nothing returns nothing
    set gg_trg_YouGuanPaiXie = CreateTrigger(  )
    call TriggerRegisterTimerEventSingle( gg_trg_YouGuanPaiXie, 2.00 )
    call TriggerAddAction( gg_trg_YouGuanPaiXie, function Trig_YouGuanPaiXie_Actions )//这里有泄漏吧
endfunction
//这样有泄漏了吧[/codes]

下面那个是触发转的J,要是这个有泄漏那每个触发都有泄漏么?
 楼主| 发表于 2008-2-26 11:48:01 | 显示全部楼层
这个没人知道么?
回复

使用道具 举报

发表于 2008-2-26 11:56:41 | 显示全部楼层
我没看出来第三段有啥问题~~

楼主向我解释一下哪里有泄漏吧?~~

明显下面那个gg_trg_YouGuanPaiXie 是全局变量好不好~~

正常的触发器就算不能被重用表空间~~又能有什么损失呢~~就算来它100个触发好了~~又能占了多少空间~~浪费多少查表效率呢~~何况这些表空间都是可达的~~

像那种用于重复创建触发器的情况~~才需要这样排除泄漏啊~~


另一方面~~这个触发由用途来看~~似乎只是一次性的~~相比起set null这种小事情~~这样的触发用完后destroy掉才能节省更多的内存吧?~~
回复

使用道具 举报

发表于 2008-2-26 12:44:46 | 显示全部楼层
另一方面~~如果你不把触发destroy掉的话~~

表空间即时变量连接数变成0了也依然还不会被重用~~因此这样单纯的set null又有什么用呢~起不到任何排除泄漏的作用~~
回复

使用道具 举报

 楼主| 发表于 2008-2-26 13:48:14 | 显示全部楼层
[codes=jass]function YouGuanPaiXie_Actions takes nothing returns nothing
      call QuestMessageBJ( GetPlayersAll(), bj_QUESTMESSAGE_UPDATED, "学习JASS" )
      call DestroyTrigger(GetTriggeringTrigger())
endfunction

function YouGuanPaiXie takes nothing returns nothing
      local trigger trig = CreateTrigger(   )
      local triggeraction trigact = TriggerAddAction( trig, function YouGuanPaiXie_Actions )
      call TriggerRegisterTimerEventSingle( trig, 2.00 )
      set trig = null
      set trigact = null
endfunction

//=======================================================

call TriggerRemoveAction(trig, function YouGuanPaiXie_Actions)
function YouGuanPaiXie_Actions takes nothing returns nothing
      call QuestMessageBJ( GetPlayersAll(), bj_QUESTMESSAGE_UPDATED, "学习JASS" )
      call DestroyTrigger(GetTriggeringTrigger())
endfunction

function YouGuanPaiXie takes nothing returns nothing
      local trigger trig = CreateTrigger(   )
      call TriggerRegisterTimerEventSingle( trig, 2.00 )
      call TriggerAddAction( trig, function YouGuanPaiXie_Actions )
      call TriggerRemoveAction(trig, function YouGuanPaiXie_Actions)
      set trig = null
endfunction
//=======================================================
[/codes]

是不是这两种排泄方法都可以?
上面那个泄露是我理解错了
谢谢Renee大人
回复

使用道具 举报

发表于 2008-2-26 13:59:54 | 显示全部楼层
厄~~就排除泄漏来说是没错了~~可是似乎语法上有问题~~

如果你刚一Create就Destroy的话~~这个触发根本不会执行了~~

一般用完一次后销毁的触发~~Destroy()函数都是放在动作里的吧?~~


另外~~如果你创建一个对象的时候根本没有用任何变量指向它~~那么销毁它的时候也就不用什么set null了~~因为变量连接数本来就是0~~
回复

使用道具 举报

 楼主| 发表于 2008-2-26 14:57:07 | 显示全部楼层

受教了
感谢Renee大人
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 点一下

本版积分规则

Archiver|移动端|小黑屋|地精研究院

GMT+8, 2024-5-18 11:02 , Processed in 0.035501 second(s), 18 queries .

Powered by Discuz! X3.5

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表