You are REAL smart to ask that before just disconnecting it like most people do. If you have a power outlet inside the car or a cigarette lighter socket, check those to see if they operate normally after the ignition switch has been off for ten minutes or longer. If one of them does, you can use a plug-in device that has a 9-volt transistor battery attached. That 9 volts is sufficient to keep the many computer memory circuits alive. It's important to not turn on the ignition switch AND to not open any door while the battery is disconnected. Doing either of those things will turn on lights and / or computers, and that could require three to eight amps which that little battery can't deliver. Its voltage will get sucked down too low to run the memory circuits.
If there's an under-hood lamp, unplug that too. Once everything is off, wait at least 20 minutes before disconnecting the battery. Some computers have to go to "sleep mode", and they can draw up to three amps for up to 20 minutes. Anytime the battery is reconnected, those go back to "wake" mode and will take up to another 20 minutes to shut down. The transistor battery can't supply that either.
Some accessories remain on for a few minutes in some car models after the ignition switch is turned off. That's to allow you to roll power windows up and things like that. After that system has timed out, if the outlets inside the car don't stay on, I use a small battery charger set to its lowest setting to maintain the memories, but there are some dangers with this method. First of all, you risk bumping one of the clamps and making it pop off. At that point you're done. If any computers are going to lock up, they will have done it before you can get that clamp back on. Second, you have to watch the positive battery cable that it never touches anything metal on the car and shorts out. Most cars today have the batteries packed away in inaccessible places so there are jump-start terminals within easy reach under the hood. That's nice for connecting the battery charger but you still have to be careful to not let the positive cable at the battery touch anything metal on the car. Since those cables are stiff and can have a mind of their own, I wrap a rag around it after it's disconnected from the battery.
Keep in mind too that batteries provide a very smooth and steady 12 volts. Battery chargers deliver a pulsing 0 - 18 volts. Computer modules have capacitors in their power supply regulator circuits to smooth those pulsations out but they were never meant to handle the large voltage pulses from a battery charger. To keep those voltage pulsations to a safe level, always keep the charger on its lowest setting. Even that setting is capable of delivering way more current than will be needed.