1. An image forming apparatus having a main controller for controlling an access to a main memory, the image forming apparatus comprising: a determination unit configured to determine whether the main memory is a non-volatile memory or a volatile memory; a storage unit configured to store a result of the determination by the determination unit in a non-volatile manner; and an erasing unit configured to erase data stored in the main memory when transition is made to a power off state or a sleep mode when the determination unit determines the main memory is the non-volatile memory.