Apparatus is provided for use in a stomach of a subject. The apparatus includes a gastric balloon and an anchor coupled to the gastric balloon. The anchor includes a flexible tube, which, when in a relaxed position, is shaped so as to define a portion that prevents the anchor from passing into a duodenum of the subject. The anchor also includes one or more shape-controlling elements coupled to the portion and configured to control a shape of the portion. Other embodiments are also described.