Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Android Android Data Persistence CRUD Operations with SQLite Starting a Database Transaction

1 Answer

Best way is to close it after each transaction.

As Database consumes memory, and if you aren't using it at the moment but still has it in memory then you're wasting memory which other processes or activities could use.

Best approach I think would be to store transactions in batch and then in the end perform them all in a bulk in stead of one by one so that you open and close Database only when you have a certain amount of transactions ready.

I hope it answers your question, Have a good day and Happy Coding :)

  • Zain