Without more information on what gun you’re thinking of placing on a magnet for what purpose (within reach of the driver? Hidden? Loaded? Being transferred from belt carry? Immediate access necessary? Etc.), it’s hard to make a single recommendation for you.
I use a strong, oblong gun magnet on the side of my bed. It holds the gun securely on the side of the slide without marring because of a thin rubber coating on the magnet. I have not found any degree of magnetism transferred to the gun that interferes with operation.
It is a stronger, bigger magnet than the first one I tried, which was neither very secure nor IMO safe because it had a tab to keep the gun from rotating. That tab could easily end up in the trigger guard and cause a negligent discharge. Don’t buy such a unit.
Some steels on guns are less magnetic than others. Know your gun.
Shear strength is different than separation strength, much like Velcro. If you directly pull two mating pieces of Velcro apart, they separate as they should. However, if you try to slide Velcro apart laterally, there is much greater force involved. Magnets have similar properties.
So, if you want to mount the magnet facing down so the gun is attached to the magnet by hanging underneath it, the jarring motions of a moving vehicle would have the easiest time magnifying gravity and separating the gun from the magnet. This is dependent on how strong the magnet is, how heavy the gun is, and how much surface area contact there is between the gun and the magnet.
If you mount the magnet vertically and the gun attaches vertically, traveling bumps and jarring are vertical forces on both the gun and the magnet, and again, depending on steel, weight of gun and area of contact, it is much more difficult for the gun to separate from the magnet vertically. Manually removing the gun laterally is not hard.
Since most magnets hold the gun without anyway to protect the trigger from moving and firing, most magnet companies recommend mounting the gun without a round in the (next firing) chamber. For a semi-auto, this would mean you would have to rack the slide to get the gun into action. At least one manufacturer takes advantage of the increased shear strength of the magnet and directs that the slide will stay in place in/on the magnet as the grip is manipulated to load a round into the chamber. You may lose some time and surprise doing this if speed is required. However, once loaded, peeling the handgun away from the magnet is easy enough.
A solution for me for an accessible, safe, vehicle mount would be to have a properly molded holster for the specific gun being carried mounted vertically to some surface. The trigger would be covered so the gun could be loaded, although as with any off body carry a manual safety is wise. The holster could be mounted with corresponding magnets, or enough Velcro, or more permanently, to keep the whole rig safe from jarring, but quickly accessible. If quick access is not a needed feature, then many different options open up.
I would not trust even a strong magnet to hold a loaded gun with an uncovered trigger through rough travel, even with a manual safety. Visibility/theft is another consideration for mounting.
If transferring a personally carried CCW to a vehicle magnet, one would probably unload the chamber. That’s an administrative act which should be done as infrequently as possible, and probably not in one parking lot after another—with the accompanying reloading for carrying.
If you have a gun you normally carry on your belt, it is best to keep it there while driving. I find AIWB with even a full size M&P 9mm in a properly set up Kydex holster works fine and is always safe, loaded, easily and quickly accessible, concealed, sufficiently comfortable, and does not require repetitive administrative loading procedures. It is not likely to jar loose and disappear in an accident, becoming unusable.
Just some random early morning thoughts. Glad to hear different experiences or opinions.