copy_colormap_and_free/2
     copy_colormap_and_free(+Old_cmap, -New_cmap)
     

New_cmap is a newly allocated, non-shared, colormap containing all the colors you have allocated out of Old_cmap (which is probably shared).