0123What to do if you get a System.OutOfMemoryException Error by Buzzler DISCLAIMER: Attention! The methods described in this lets_call_it_a_tutorial are by no means foolproof, entirely safe or whatever appropriate adjectives come to your mind. If you mess this up you could corrupt your system (the software part)! You've been warned! The Problem ----------- Now that we got this over with let's begin. Say you're playing in a pretty big and old neighbourhood, have most or all of the EPs and use SimPE to edit said neighbourhood from time to time. Bad news for you cause you're pretty much doomed to encounter an out of memory error in SimPE sooner or later the exact error message being "Exception of type 'System.OutOfMemoryException' was thrown.". Be aware though that this does not really deserves to be called a bug it's more like reaching limits that weren't expected to be reached. If you got the error and are done whining and cursing entities of choice, start the Task-Manager, hit the process view and then re-enact what you did to make SimPE spout the error message. Observe the memory usage of the SimPE process. Does it rise and rise and if the memory usage is at around 1.7GB (might be 1.6GB or 1.8GB as well) the error occurs? Congrats you've got what I'm talking about. Background Information ---------------------- Skip this if you don't want to know what's going on. When the first WindowsNT (and XP and Vista are direct descendants of NT so the same still applies to them) was developed MS made the convention that the 4GB of address space that can be managed using 32Bits would be divided into 2GB for programs and 2GB for "kernel and executive services", so SimPE can theoretically allocate up to 2GB of memory. In the real world the maximum memory usage is nowhere near these 2GB but usually in the region of 1.6-1.8GB and heavily dependent on what the program in question is trying to do. The cause of this is called "memory fragmentation" and is pretty much the same as the disc fragmentation appearing on hard drives but while a file just can be split into pieces (=file fragmentation) if there's not enough continuos space on the drive, the memory management of the OS cannot do this. If an application tries to allocate memory it's either getting it in one piece or it's getting nothing and that is exactly what is happening to SimPE: There are still gaps on the bench but not enough space to squeeze SimPE's big butt in. A word about swap size or more correctly pagefile size - skip this if you don't want to know what this Buzzler whoever he is thinks about the world. If you encountered the mentioned problem and asked for help maybe someone recommended increasing the size of the pagefile. Probably someone even hinted the pagefile should be at least 1.5 times as big as the amount of physical RAM. Given the fact that the application runs out of memory at around 1.7GB of memory usage this is just plain nonsense. The size of the pagefile doesn't affect the above mentioned 2GB limit for 32Bit programs at all. And since the pagefile has to be addressed just like the physical RAM, do you think the size of the pagefile could have any effect on the 4GB address space limit of 32Bit operating systems? In fact if you got 4GB of RAM and a 32Bit OS the pagefile is pretty much of no use at all. And all these "facts" on how the pagefile should be 1.5 as large as the RAM were just nonsense to begin with, someone somewhere started it, it got repeated over and over again by people who have no clue how the memory management of a modern OS works and right now this "truth" can't be killed anymore even if you try to stake its heart. The Solution ------------ Ok enough nagging we want to get rid of the issue and yes there is a possible way but like stated above it is potentially dangerous and will pretty much definitely end in disaster if you don't do exactly what I say. Ok, now stand on one leg and bark like a dog! Well it was worth a try... Part 1. Windows Configuration This part only applies to 32Bit operating systems so if you're running a 64Bit-Windows, you don't need to, you should not, you MUST not do this! Just skip all of the following and just read and do the part about the LAA-flag at the end. I stated above that Windows splits up his 4GB address space into 2GB for programs and 2GB for "kernel and executive services" but luckily this is not set in stone. (Did you notice the part about the "4GB address space" and come to the conclusion that this does not apply to 64Bit operating systems because they got a much larger address space? Too bad. That would have been very smart of you.) Windows XP (C:\boot.ini) On Windows XP (and Windows 2000 and Windows 2003) there's a switch that can be set in the boot.ini to change the 2GB/2GB divide to 3GB/1GB. This is where the fun starts. Start Windows Explorer and open the root directory of the drive where your Windows is installed (C:\ for the most installs). If you don't see a file named boot.ini, then check your 'View' options. As this is the file that needs changing, also check that the file is not 'Read-only'. See the end of this doc if you need help with the Read-only or View options. Double click on boot.ini to open it. Under [operating systems] should be a string that should look more or less like this: multi(0)disk(0)rdisk(0)partition(1)\WINDOWS="Microsoft Windows XP Home Edition" /noexecute=optin /fastdetect Copy it and insert it right below the original string - and copy it from your boot.ini not from this post! Add "/3GB /userva=2900" (without the quotation marks) to the inserted string and add something to the Windows and so on within the quotation marks for example 3GB so they can be distinguished at bootup. Now the boot.ini should look something like this: [boot loader] timeout=30 default=multi(0)disk(0)rdisk(0)partition(1)\WINDOWS [operating systems] multi(0)disk(0)rdisk(0)partition(1)\WINDOWS="Microsoft Windows XP Home Edition" /noexecute=optin /fastdetect multi(0)disk(0)rdisk(0)partition(1)\WINDOWS="Microsoft Windows XP Home Edition - 3GB" /noexecute=optin /fastdetect /3GB /userva=2900 Don't change anything in this multi(0)rdisk(0)... part because you'll make your system unbootable that way! If you now reboot your computer the boot menu should pop up giving you the choice between the two possibilities, the first one is your normal unaltered 2GB/2GB-Windows and the second is the altered 3GB/1GB-Windows. Windows Vista If you use Vista 32Bit the above method is not possible sadly enough. I found this alternative: To enable the 3GB switch on Windows Vista 1. Right-click Command Prompt in the Accessories program group of the Start menu. Click Run as Administrator. 2. At the command prompt, enter "bcdedit /set IncreaseUserVa 2900" 3. Restart the computer. To turn off the 3GB switch 1. Right-click on Command Prompt in the Accessories program group of the Start menu. Click Run as Administrator. 2. At the command prompt, enter "bcdedit /deletevalue IncreaseUserVa" 3. Restart the computer. Since I don't have Vista I couldn't test this and I said sadly because unlike the method for XP there's no safety net but if you run into any problems and can't turn off the switch the regular way, you should still be able to safe boot your machine and then disable it. Part 2. The LAA-Flag Now we have Windows where we want it. It is able to provide up to 3GB of memory to 32Bit programs (64Bit OS's can by default provide up to 4GB to 32Bit programs) but the programs have to explicitly state that they're able to handle more than 2GB of memory or Windows won't provide them more. This is where LAA (large address awareness) comes into play. Download NT-Core (http://ntcore.com/exsuite.php) and install it. Now open CFF Explorer and in CFF Explorer open the SimPE-Executable. Click on "File Header" -> "Characteristics / Click here" and check "App can handle >2gb address space". Save and exit. Now SimPE is able to handle more than 2GB of RAM and the out of memory problem should be history, for now. Final Words ----------- I strongly recommend you to use the 3GB switch for SimPE only (and maybe testing purposes or purposes you found to be safe during testing or whatever) and don't leave it set all the time (XP users are safe to leave the entry in their boot.ini though). Don't be surprised if applications run unstable with the 3GB switch set! For example: While I tested Sims2 crashed within seconds after entering a neighbourhood if the 3GB-switch was set. (When you read this did you think "Wow, sounds kinda risky. I'd better update my backup before I try this"? Too bad. That would have been very smart of you.) Thanks to tunaisafish for proofreading and recommending the use of the 3GB-switch to me in the first place. Misc ---- The 'Read-only' attribute will stop you editing a file. To view/change it... In Windows Explorer right-click the file and choose 'Properties'. At the bottom of the popup Attributes. Uncheck the box next where it says 'Read-only' to make it editable (or writable). Displaying Hidden files. By default, Windows will hide the files that control your system configuration to protect you from yourself. In Windows Explorer, From the menubar choose "Tools -> Folders Options". Select the 'View' tab. Select the "Show hidden files and folders" button. Click 'OK'.