Improve publish/subscribe memory management