Hi,

>Sorry, I forgot to add: sqlite3_column_name(16). Currently I
>let MS .NET free memory from that as well.

You shouldn't do that. with sqlite 2 you had to free some memory when calling sqlite_compile using sqlite_freemem. With sqlite3 that is no longer needed, also not when calling sqlite3_errmsg.

With windows and .net on windows, dll's and the main application do not share the same memory manager. Dll's must handle their own memory, and the main app isn't even allowed to free or reallocate that.

sqlite3_free is not intended for freeing anything except two printf functions:
http://www.sqlite.org/capi3ref.html#sqlite3_free
  void sqlite3_free(char *z);
Use this routine to free memory obtained from sqlite3_mprintfor sqlite3_vmprintf

Maybe docs should add with sqlite3_errmsg[16] that freeing is not needed.

regards,

rene


Rob Lohman wrote:

Sorry, I forgot to add: sqlite3_column_name(16). Currently I
let MS .NET free memory from that as well.

Thanks,

Rob

----- Original Message ----- From: "Rob Lohman" <[EMAIL PROTECTED]>
To: <sqlite-users@sqlite.org>
Sent: Friday, October 21, 2005 7:05 PM
Subject: [sqlite] who is responsible for memory


Hi everyone,

A couple of months ago I started writing a Microsoft .NET
(1.1 at the moment, but it will be 2.0) wrapper around SQLite.
I know a couple of those already exist, but for various
reasons these do not meet my requirements.

Everything is looking fine except for managing memory. I've
had some memory problems according to some profilers
which I've seem to have fixed but I want to make sure. I
have looked at the everything in the site but with certain
(SQLite) functions it is unclear to me who is responsible
to clean up any allocated memory.

Now I seem to remember from long long ago that there
where some "rules" in C(++) who is responsible in which case
with a library or DLL, but I have no idea if that is true or what
those rules would be.

The first sign of trouble began with the sqlite3_errmsg(16)
function. I had MS .NET release that memory which seemed
a bad thing to do. After I stopped doing that, and I assume
SQLite frees it, everything appears fine.

That let me to wonder about the following functions:

- sqlite3_column_blob/text(16)

With these functions I copy out the data and (hopefully) let
SQLite free the memory.

- sqlite3_libversion

I let the MS .NET framework free this memory.

At the moment this is inconsistent as you can see. Is any of
this correct or?

Since sqlite3_bind_blob/text(16) let me select either transient
or static I'm always responsible for that memory, right?

Any clarification on this matter will be greatly appreciated.

Thanks!

Best,

Rob Lohman


Reply via email to