To create a new colormap when the allocation out of a previously shared colormap has failed because of resource exhaustion, use XCopyColormapAndFree().
To destroy a colormap, use XFreeColormap().