title: Correct way to instantiate a groovy class
body: <p>I want to instatiate a groovy class and i have some concerns</p>
  
  <p>My first choice is to use <a href="http://docs.groovy-lang.org/latest/html/api/groovy/lang/GroovyShell.html" rel="nofollow noreferrer">GroovyShell</a> :</p>
  
  <p>groovy-script:</p>
  
  <pre><code>class Foo {
      public String doStuff(String stuff) {
          return stuff + "_utils";
      }
  }
  new Foo(); // ??
  </code></pre>
  
  <p>main-script :</p>
  
  <pre><code>GroovyShell shell = new GroovyShell();
  Script script = shell.parse(new File(path));
  def clazz = script.run();
  String result = clazz.doStuff("test");
  print(result); // test_utils;
  </code></pre>
  
  <p>The second option is to use <a href="http://docs.groovy-lang.org/latest/html/api/groovy/lang/GroovyClassLoader.html" rel="nofollow noreferrer">GroovyClassLoader</a> :</p>
  
  <p>groovy-script</p>
  
  <pre><code>class Foo {
      public String doStuff(String stuff) {
          return stuff + "_utils";
      }
  }
  </code></pre>
  
  <p>main-script</p>
  
  <pre><code>GroovyClassLoader loader = new GroovyClassLoader();
  Script script = loader.parseClass(new File(path))
  Object clazz = script.newInstance();
  Object[] args = new Object[1];
  args[0] = "test";
  String result = clazz.invokeMethod("doStuff", args);
  print(result) // test_utils
  </code></pre>
  
  <p>Both will run fine, i would prefer to use GroovyShell because i use it everywhere in my current code, but i don't know if <code>new Foo()</code> inside my scripts can cause any memory leaks. Is it possible?</p>