title: In Scene2d, when an Action is completed, it is removed from the Actor but it's not put back in the Pool
body: <p>In Scene2d, when an Action is completed, it is removed from the Actor but it's not put back in the Pool.</p>
  
  <p><strong>Action.class</strong></p>
  
  <pre><code>/** Sets the actor this action will be used for. This is called automatically when an action is added to an actor. This is also
       * called with null when an action is removed from an actor. When set to null, {@link #reset()} is called.
       * &lt;p&gt;
       * This method is not typically a good place for a subclass to query the actor's state because the action may not be executed
       * for some time, eg it may be {@link DelayAction delayed}. The actor's state is best queried in the first call to
       * {@link #act(float)}. For a TimedAction, use TimedAction#initialize(). */
      public void setActor (Actor actor) {
          this.actor = actor;
  
      }
  
      /** Resets the optional state of this action to as if it were newly created, allowing the action to be pooled and reused. State
       * required to be set for every usage of this action or computed during the action does not need to be reset.
       * &lt;p&gt;
       * The default implementation calls {@link #restart()}. Also, if the action has a {@link #setPool(Pool) pool} then the action is
       * {@link Pool#free(Object) returned} to the pool.
       * &lt;p&gt;
       * If a subclass has optional state, it must override this method, call super, and reset the optional state. */
      public void reset () {
          restart();
          if (pool != null) {
              pool.free(this);
              pool = null;
          }
      }
  </code></pre>
  
  <p>It seems that the Action reset() method (which is the only place where the sending to the Pool is done)(1) it's never called when the Actor's actions array is cleared, and subsequently the backup to the pool doesn't occur...</p>
  
  <p>(1) - In previous versions we could override the finish() method and sent the Action to the pool, but the method it's not available anymore...</p>
  
  <p>I got this problem when I tried to extend the Action class to this one :</p>
  
  <p><strong>TimelineAction.class</strong></p>
  
  <pre><code>/**
   * Timeline action runs a Timeline (separate from the TweenManager to avoid a second manager/loop cycle)
   * with Scene2d
   */
  public class TimelineAction extends Action {
  
      private static final Pool&lt;TimelineAction&gt; pool = new Pool&lt;TimelineAction&gt;() {
  
          @Override
          protected TimelineAction newObject() {
  
              Gdx.app.log("LOG", "TimelineAction action = new TimelineAction();");        
              TimelineAction action = new TimelineAction(); 
  
              return action;
          }
  
      };  
  
      private Timeline timeline;
      private boolean done;
  
      /**
       * Get instance from pool.
       * 
       * @param timeline
       *            The associated tween.
       * 
       * @return Pooled instance.
       */
      public static TimelineAction createTimelineAction(Timeline _timeline)   {
  
          TimelineAction action = pool.obtain();
  
          action.setPool(pool);
  
          action.setTimeline(_timeline);      
  
          return action;
      }
  
      @Override
      public boolean act(float delta) {
  
          done = timeline.isFinished(); 
          if (!done) {
              timeline.update(delta);
          } else {
              Gdx.app.log("LOG", "timeline.finished()");          
              timeline.free();
              timeline = null;                            
          }
          return done;
      }
  
      private void setTimeline(Timeline timeline) {
  
          this.timeline = timeline;
      }
  
  }
  </code></pre>
  
  <p>Original idea from <a href="http://www.netthreads.co.uk/2012/02/05/libgdx-scene2d-demo-with-java-universal-tween-engine/" rel="nofollow"><code>netthreads</code></a></p>
  
  <p>I noticed that every time an Action is added, it creates a new object(<code>TimelineAction action = new TimelineAction()</code> ) instead of returning a pooled one.
  Then I tried to trace the Action ending, by overriding his <code>reset()</code> method, to find out if it's ever called... But it's not.</p>
  
  <pre><code>@Override
  public void reset () {
  
      Gdx.app.log("LOG", "reset()");
      super.reset();
  }
  </code></pre>
  
  <p>Btw, the Timeline and it's Tweens objects are successfully sented to the respectively Pools, after TimelineAction completed (2):</p>
  
  <p>(2) - The Timeline.getPoolSize() returns 1 and the Tween.getPoolSize() returns 2</p>
  
  <pre><code>actor1.addAction(TimelineAction.createTimelineAction(
              Timeline.createSequence()
                      .push( Tween.to(logo_MUTANT, Element2DAccessor.POS_XY, 3f)
                              .waypoint(400, 800)
                              .waypoint(200, 400)
                              .waypoint(100, 200)
                              .target(0,0)
                           )
                      .ease(Quad.INOUT).path(TweenPaths.catmullRom)).push(Tween.call(callback).setCallbackTriggers(TweenCallback.BACK_COMPLETE)).repeatYoyo(1, 0.5f).start()));
  </code></pre>
  
  <p>So, i need some help over here, please! :S</p>
  
  <p>Thanks in advance and please, excuse my poor English. ;)</p>
  
  <p>Libgdx version 0.9.6 (24-07-2012)</p>