Fix ResizeBuffer error by disposing the object returned by context.Target