CPU running high!

I´m doing a video recorder but have some problem with CPU running high. When connecting to camera and microphone the CPU started to run high. I couldn´t locate the problem so I rewrote the code and after that, there was no problem. The thing is that I still can´t see what the problem was. There are nothing special about the code. But now I ran into a new problem: When I close the NetStream - ns.close() to unpublish - the CPU starting to run high again. What? When starting to append to the same NetStream the problem is gone. What?

Someone who´s discovered same problem? A hardware problem on my MacBook? A software problem? A code problem? I´m running on Mac OS X Leopard using Red5 streaming server.