From 87de418446e0c34fc923656ae140f2be5eddebdd Mon Sep 17 00:00:00 2001 From: Chris Boden Date: Wed, 4 Jun 2014 20:59:10 -0400 Subject: [PATCH] Revert "Revert "Fixed a memory leak when a connection is closed the topics should also be removed if they are empty"" This reverts commit c86fdadcdec7ad59724502ca4bd50d4cc4986980. --- src/Ratchet/Wamp/TopicManager.php | 7 +++++-- tests/unit/Wamp/TopicManagerTest.php | 7 +++++++ 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/src/Ratchet/Wamp/TopicManager.php b/src/Ratchet/Wamp/TopicManager.php index bceee73..a69e315 100644 --- a/src/Ratchet/Wamp/TopicManager.php +++ b/src/Ratchet/Wamp/TopicManager.php @@ -77,8 +77,11 @@ class TopicManager implements WsServerInterface, WampServerInterface { public function onClose(ConnectionInterface $conn) { $this->app->onClose($conn); - foreach ($this->topicLookup as $topic) { - $topic->remove($conn); + foreach ($this->topicLookup as $topic => $storage) { + $storage->remove($conn); + if (0 === $storage->count()) { + unset($this->topicLookup[$topic]); + } } } diff --git a/tests/unit/Wamp/TopicManagerTest.php b/tests/unit/Wamp/TopicManagerTest.php index 0c31d9a..7439064 100644 --- a/tests/unit/Wamp/TopicManagerTest.php +++ b/tests/unit/Wamp/TopicManagerTest.php @@ -166,12 +166,19 @@ class TopicManagerTest extends \PHPUnit_Framework_TestCase { $method = $class->getMethod('getTopic'); $method->setAccessible(true); + $attribute = $class->getProperty('topicLookup'); + $attribute->setAccessible(true); + $topic = $method->invokeArgs($this->mngr, array($name)); + $this->assertCount(1, $attribute->getValue($this->mngr)); + $this->mngr->onSubscribe($this->conn, $name); $this->mngr->onClose($this->conn); $this->assertFalse($topic->has($this->conn)); + + $this->assertCount(0, $attribute->getValue($this->mngr)); } public function testOnErrorBubbles() {