Search code examples
xulxpcomxulrunner

What's the difference between getService() and createInstance()?


I realized that both:

Components.classes["@me.org/mycomponent;1"].createInstance();

and

Components.classes["@me.org/mycomponent;1"].getService();

works the same way to get a xul component. So, what's the difference of using one or another?


Solution

  • getService will create a singleton, whereas createInstance creates a new instance each time you call it. getService will return the same object every time.