On March 14, 2006 12:03 pm, [EMAIL PROTECTED] wrote:
> Hi all,
> I am having real problems with SQLite on Windows CE (.NET 4.1 and
> Pocket PC 2003). I have tried everything and it seems that there is a
> memory leak with SQLite on Windows CE. I have test it with SQLite
> versions 3.2.2 and 3.3.4 and SQLite seems that it reserves memory and
> doesn´t free it after using it, memery is freed only after the main
> program has finished. Take this simple example (it fails also with
> more complicated ones). I have test it using a quite big table
> (20,000 records).
>
> Please i really need help, because my program consumes all the memory
> and i need to finish it next week: Here is the sample source code to
> test (this is done with EVC 4.0 and a MFC application) void
1>CMemoryMDlg::OnButton1() {
2> char *errmsg;
3> char **result;
4> sqlite3 *db;
5> int ret, rows, cols;
6>
7> int n = sqlite3_open("\\mysqlitebd.db", &db);
8> if (db == 0) {
9> MessageBox(_T("Error openning BD"),_T(""),MB_OK);
10> return;
11> }
12> ret = sqlite3_get_table(db, "SELECT * FROM artic",
13> &result, &rows, &cols, &errmsg);
14> if (ret != SQLITE_OK) {
15> MessageBox(_T("Error en SQL"),_T("Error"),MB_OK);
16> sqlite3_free(errmsg);
17> return;
18> } else {
19> MessageBox(_T("Error on SQL sentence"),_T("Error"),MB_OK);
20> }
21> sqlite3_free_table(result);
22> sqlite3_close(db);
23>}
Looking at your code, please note that from line 12 onwards you NOW
have a database open so you have to CLOSE(db). I notice that you only
close it at line 22 but forgot/failed to do a CLOSE(db) before you
RETURN on line 17.
I recommend you check your other routines for a common fault in
forgetting to close all open handles and allocated memories before
doing a RETURN if you hit an error.
I did not test your code but note the above just from reading your
code. Other readers may point out other issues besides the one I
mentioned.
Hope that helps.