Originally posted by: JTsyo
Then conservation of energy wouldn't hold. As the object gains potential energy, the magnet has to lose of kind of energy.
Yes. An object in a magnetic field can be thought of as providing 'magnetic potential energy', in the same way as an object on top of a well has 'gravitational potential energy'.
When the object gets attracted to the magnet, it falls down the 'magnetic well', as magnetic potential energy gets converted into kinetic energy and/or gravitational potential energy. So, the magnet has provided energy to the object.
When you pull the object off the magnet - just like lifting the object out of a well, by replenishing it's gavitational potential energy, so you must provide energy to the object, replenishing the magnetic potential energy. No energy is created or destroyed.
So, where does the energy in the magnetic field come from - it comes from within the magnet. This is energy that was captured when the magnet was created. When a permanent magnet becomes permanently magnetized by an external magnetic field, the external field is weakened - it's magnetic potential energy is drained and transferred into the new magnet.
Let's say you make an electromagnet out of a coil of wire, and a metal that does not retain a magnetic field, e.g. 'soft iron'. When you apply voltage to the wire, the current ramps up gradually as the magnetic field builds up - the gradual ramping of the current is due to electrical energy being converted into magnetic potential energy. When the voltage is disconnected, the magnetic field begins to disappear and it's energy is converted back into electrical energy, which gets forced back into the electrical circuit. This electrical energy can be seen as sparks in a switch, or it can destroy electronic components like transistors, unless the circuit is able to dump the energy when the magnet is switched off. (This is a common mistake for beginners making electronically controlled relay circuits. If you don't put an energy dump diode in the circuit, the relay's magnet discharging will fry the transistors).
Now repeat this coil experiment, but instead of 'soft iron', you use a magnetic material such as magnet steel. The magnet has been magnetized and has retained some of the magnetic energy, now when the electrical current is switched off, less energy gets released, because some of the energy has been retained as magnetic energy.