My function is very complicated. After enter command user must select objects. He select the whole drawing space. After that I'm do my job - storing specified blocks and curves into my collection, doing calculations and updating blocks.
Number of all elements that I'm modifying could raise to few thousands.
I've made some tests and (even that I'm removing objects from my collection while loop) function is faster at begin and slower at the end.
I thought I can do something like this:
if (counter = 100)
but I'm getting fatal error
Maybe someone know a way to increase speed up, so I can clean memory while calculating selected objects in my function.
Its very hard to make suggestions on optimizing performance without seeing any code. If you're opening objects in a transaction to check their type is one you're interested in, then using ObjectId.ObjectClass to make the comparison could speed up processing a large drawing, and make sure you open an object for read to query it and ugradeopen when you decide to edit it, rather than opening everything fro write. You could also read through Fenton's ongoing series of blogs about API performance, starting here - http://adndevblog.typepad.com/autocad/2012/07/the-right-tools-for-the-job-autocad-part-1.html.
You weren't very descriptive, but I believe your fatal error is because you are trying to commit the transaction and then keep using it and commit it over and over again. You can't do that. Once a transaction has been committed, the only thing you can do with it is dispose it.