Use a very big swap (file) ! For Lazarus, at least 1GB is needed. On my RPi2, Lazarus installs (fpcup) and runs ok