I don't see how the code you presented could be possibly hogging your memory (that problem lies elsewhere).
Try upgrading the db version and recompiling DB_File as well as increasing the cache to alleviate the speed issue (you can't do too much, cause file-io is only so fast).