Up to Main Index                             Up to Journal for March, 2017

                     JOURNAL FOR MONDAY 13TH MARCH, 2017
______________________________________________________________________________

SUBJECT: Memory, allocations and garbage
   DATE: Mon 13 Mar 22:55:17 GMT 2017

After I updated the public dev branch with the rewritten zone loader yesterday
something didn’t feel quite right. So I started poking at the code again and
debugging the server.

Turns out my feelings were right :(

While the temporary stored was being cleared down the variable were not being
garbage collected. Turn out I has missed out a call to Thing.Close.

I also didn’t spot an instance where a door could create its ‘other side’ and
then the ‘other side’ created another ‘other side’ over the original. All to
do with maps and the way they are randomly traversed. Harmless, but fixed.

While I was debugging memory allocations I uncovered some more variables that
were not being released properly and fixed those as well. These were related
to deleting elements from a slice — as detailed in ‘Slice Tricks’ on the
golang wiki.

So I was using something like:


  s[i] = nil
  s = append(s[:i], s[i+1:])


However if the slice contains pointers or reference types it should be:


  copy(s[j:], s[j+1:])
  s[len(s)-1] = nil
  s = s[:len(s-1)]


Now I knew this already, so why didn’t I get it right the first time? I’m
guessing when I wrote the code I was still learning Go at them time…

Also while debugging memory issues I updated the stats package to give more
accurate information on memory in use[1] by the server. The figures now agree
with what the scavenger stats display — and that’s good enough for me ;)

All the above has just been pushed out to the public dev branch.

--
Diddymus

  [1] The stats show in use, allocated memory. It does not show memory
      allocated from the operating system, or agree with top, ps or any other
      OS commands and utilities. I’ve opened this can of worms enough times
      now, and hope this is the last.


  Up to Main Index                             Up to Journal for March, 2017