gmap with better memory management