When it appears that the party is detained on any process under which any other person has an interest in continuing such imprisonment or restraint, the party shall not be discharged until notice has been given to such other person or his attorney, if within the State or within 30 miles of the place of examination, to appear and object, if he sees cause. If imprisoned on any criminal accusation, he shall not be discharged until sufficient notice has been given to the Attorney General or other attorney for the State that he may appear and object, if he thinks fit.
14 M.R.S. § 5522