I have a 3gs on ios4 jailbroken with jailbreakme.com

Sometimes when I'm using an app it'll freeze up, so I hit the home button and then it takes a while to get back to the home screen. Then, when it does, nothing responds and it just sits there until either I restart it, or eventually it reboots on it's own. Any idea what's causing this? Thanks.