Skip to content

Instantly share code, notes, and snippets.

@moea
Created April 12, 2013 09:51
Show Gist options
  • Save moea/5370923 to your computer and use it in GitHub Desktop.
Save moea/5370923 to your computer and use it in GitHub Desktop.
package com.novoda.example.MemoryLeaker;
import java.util.HashSet;
import java.util.Set;
public class ToyMessageBus {
private static ToyMessageBus instance;
private final Set<Object> listeners = new HashSet<Object>();
private ToyMessageBus() {}
public static ToyMessageBus getInstance() {
// implementing this method correctly would require a separate blog post.
if(instance == null) {
instance = new ToyMessageBus();
}
return instance;
}
public void register(Object o) {
listeners.add(o);
}
public void unregister(Object o) {
listeners.remove(o);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment