void run(){ while(_run) { bytebuffer bb(); // here is where the leak occurs. // bb never falls out of scope. // the problem is corrected by putting the buffer // object outside the loop and flushing it every iteration, // but normally in C++, it would fall out of scope at // the end of the loop. bytebuffer is registered as a reference // type. irc_event event(this); int chars = sock.receive(bb,4098); if(chars>0) { string msgstr=bb.str; string@[] messages = split(msgstr,"\r\n"); for(int y=0;y<messages.length();y++) { /*for(int h=0;h<messages[y].length();h++) { // remove any and all newlines from the message!!! if(messages[y][h]!=CR || messages[y][h]!=LF) { b.push_back(messages[y][h]); } }*/ event.raw_string=messages[y]; IRC_EVENT_HANDLER@ evt; if(event.prefix=="PING") { events.get("PING",@evt); evt(event); } if(event.prefix=="ERROR") { _run=false; send_raw("QUIT\r\n"); sock.close(); } else if(events.exists(event.command)) { events.get(event.command,@evt); evt(event); } else { events.get("DEFAULT",@evt); evt(event); } } } }}
Script Based Memory Leak Found
Hey, I discovered recently that the following code will produce a memory leak with the latest AngelScript.
Since it is a reference type the object will survive until all references to it are released, even if the original declaration goes out of scope.
How is the socket.receive() method implemented? Is it receiving the bytebuffer by handle? If so, is it properly releasing it before returning?
How is the socket.receive() method implemented? Is it receiving the bytebuffer by handle? If so, is it properly releasing it before returning?
AngelCode.com - game development and more - Reference DB - game developer references
AngelScript - free scripting library - BMFont - free bitmap font generator - Tower - free puzzle game
Now that you mention it, I never do add a reference to the bytebuffer. It is being received by handle.
EDIT: Yep, it was my code. Remember to Release your passed handles kids.
[Edited by - _orm_ on July 4, 2010 1:52:45 PM]
EDIT: Yep, it was my code. Remember to Release your passed handles kids.
[Edited by - _orm_ on July 4, 2010 1:52:45 PM]
Since it receives the handle to the bytebuffer it must release it before returning.
AngelCode.com - game development and more - Reference DB - game developer references
AngelScript - free scripting library - BMFont - free bitmap font generator - Tower - free puzzle game
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement