  We investigate the instability of purely poloidal magnetic fields in
nonrotating neutron stars by means of three-dimensional general-relativistic
magnetohydrodynamics simulations, extending the work presented in Ciolfi et al.
(2011). Our aim is to draw a clear picture of the dynamics associated with the
instability and to study the final configuration reached by the system, thus
obtaining indications on possible equilibria in a magnetized neutron star.
Furthermore, since the internal rearrangement of magnetic fields is a highly
dynamical process, which has been suggested to be behind magnetar giant flares,
our simulations can provide a realistic estimate of the electromagnetic and
gravitational-wave emission which should accompany the flare event. Our main
findings are the following: (i) the initial development of the instability
meets all the expectations of perturbative studies in terms of the location of
the seed of the instability, the timescale for its growth and the generation of
a toroidal component; (ii) in the subsequent nonlinear reorganization of the
system, ~90% of magnetic energy is lost in few Alfven timescales mainly through
electromagnetic emission, and further decreases on a much longer timescale;
(iii) all stellar models tend to achieve a significant amount of magnetic
helicity and the equipartition of energy between poloidal and toroidal magnetic
fields, and evolve to a new configuration which does not show a subsequent
instability on dynamical or Alfven timescales; (iv) the electromagnetic
emission matches the duration of the initial burst in luminosity observed in
giant flares, giving support to the internal rearrangement scenario; (v) only a
small fraction of the energy released during the process is converted into
f-mode oscillations and in the consequent gravitational-wave emission, thus
resulting in very low chances of detecting this signal with present and..
