If a judgment of acquittal is entered and the defendant is under custody, he shall be released forthwith, unless by reason of other pending causes he should remain in custody, and if he is on bail, it shall be exonerated or his money refunded as the case may be.