Up to Main Index                               Up to Journal for May, 2012

                      JOURNAL FOR TUESDAY 22ND MAY, 2012
______________________________________________________________________________

SUBJECT: When something does nothing but means something...
   DATE: Tue May 22 20:58:57 BST 2012

My doesn't time fly - seems like only last Thursday I was writing in the
journal. So have I accomplished much in the last 5 days? No *sigh*

I've done a lot but accomplished little. At the moment I'm still trying to
work out what the heck is causing a memory leak in WolfMUD's client and
networking code. After adding finalizers to everything I found out what wasn't
causing objects to be kept hanging around. Also cleaned up a few corner cases.

I'm slowly narrowing things down and the highly suspect cause seems to be
Goroutines. Well sort of - they seem to be acting like closures even though
I'm not using function literals. For example:


  func (w *World) startPlayer(conn *net.TCPConn) {
    c := client.New(conn)
    p := player.New(w)

    p.AttachClient(c)

    //w.locations[1].Broadcast(
    //  []thing.Interface{},
    //  "There is a puff of smoke and %s appears spluttering and coughing.",
    //  p.Name(),
    //)

    go c.Start()
  }


After accepting a network connection this function is called to create a
client and an in world Player. The two are stitched together and the client
kicked off to do IO in a new Goroutine. Except if I include the commented out
lines the client and player objects are not garbage collected when the
connection dies and the Goroutine ends. Comment out the code and everything is
hunky dory. So what is in Broadcast? Where are we taking a reference and
squireling it away?


  func (l *Location) Broadcast(
    ommit []thing.Interface, format string, any ...interface{}) {
  }


Oh well there's your prob... erm ... oh, nothing ;) So ... comment out out the
function that does nothing currently and it works? What I *think* is happening
is the call is creating reference that the closure is holding onto... perhaps?

--
Diddymus


  Up to Main Index                               Up to Journal for May, 2012