355. If a ship is finally detained under this Chapter, or if it appears that a ship provisionally detained was at the time of such detention unsafe or if a ship is detained in pursuance of any provision of this Part which provides for the detention of a ship until a certain event occurs, the owner of the ship shall be liable to pay to the Government the costs of and incidental to the detention and survey of the ship; and the ship shall not be released until such costs are paid.