The default setting for Terminal.app is to keep an infinite history for the window. All the data is stored in RAM, so closing the window will release the history and the RAM it uses.
Terminal.app has a preference to control the number of lines saved in the history buffer. This setting can be used to control Terminal.app's RAM usage.