• 🏆 Texturing Contest #33 is OPEN! Contestants must re-texture a SD unit model found in-game (Warcraft 3 Classic), recreating the unit into a peaceful NPC version. 🔗Click here to enter!
  • 🏆 Hive's 6th HD Modeling Contest: Mechanical is now open! Design and model a mechanical creature, mechanized animal, a futuristic robotic being, or anything else your imagination can tinker with! 📅 Submissions close on June 30, 2024. Don't miss this opportunity to let your creativity shine! Enter now and show us your mechanical masterpiece! 🔗 Click here to enter!

Strange memory leaks

Status
Not open for further replies.

EdgeOfChaos

E

EdgeOfChaos

So, I decided to use the function from this thread to discover whether I had memory leaks: http://www.hiveworkshop.com/forums/triggers-scripts-269/things-leak-35124/

Specifically, this is what I wrote.
JASS:
library Debug initializer onInit
    
    globals
        private boolean debugOn = true
        private boolean handleCountOn = true
        private timer t
        private constant real PERIOD = 1.
    endglobals
    
    private function handleCount takes nothing returns nothing
        local location L = Location(0,0)
        call BJDebugMsg(I2S(GetHandleId(L)-0x100000))
        call RemoveLocation(L)
        set L = null
    endfunction
    
    private function onInit takes nothing returns nothing
        if(debugOn and handleCountOn)then
           set t = CreateTimer()
           call TimerStart(t,PERIOD,true,function handleCount)
       endif
    endfunction
    
endlibrary

This works fine, and it shows the number of handles I have. The confusing thing was when it said that the number of handles were increasing by thousands every second - i.e. thousands of memory leaks. I had been coding carefully, so I went through and disabled all the triggers until I found what caused it.

This caused the leaks:
JASS:
    private function bSleep takes nothing returns nothing
        local group g = CreateGroup()
        call GroupEnumUnitsInRect(g,GetPlayableMapRect(),Filter(function sleepFilter))
        call DestroyGroup(g)
        set g = null
    endfunction
I messed around with it for a while and found that if I removed the DestroyGroup call, it would no longer leak, like this:
JASS:
    private function bSleep takes nothing returns nothing
        local group g = CreateGroup()
        call GroupEnumUnitsInRect(g,GetPlayableMapRect(),Filter(function sleepFilter))
        set g = null
    endfunction
But from my knowledge of JASS, I would have expected the first one would not leak, and the second one would. It turned out to be the opposite when I coded it. I'm wondering why, or if there is some problem with the code that showed the handle count in the first place.
 
Level 7
Joined
Oct 19, 2015
Messages
286
What does the surrounding code look like, like the sleepFilter and whichever function calls bSleep? Can you reproduce this bug in an empty map with just this code?
 

EdgeOfChaos

E

EdgeOfChaos

I removed all code from sleepFilter (just has a return false)
This is the code that calls the function
JASS:
    private function onInit takes nothing returns nothing
        call TimerStart(t,1,true,function bSleep)
    endfunction
I'll try it in an empty map.
 
Status
Not open for further replies.
Top