xref: /sqlite-3.40.0/test/malloc5.test (revision eee4c8ca)
10190d1daSdanielk1977# 2005 November 30
20190d1daSdanielk1977#
30190d1daSdanielk1977# The author disclaims copyright to this source code.  In place of
40190d1daSdanielk1977# a legal notice, here is a blessing:
50190d1daSdanielk1977#
60190d1daSdanielk1977#    May you do good and not evil.
70190d1daSdanielk1977#    May you find forgiveness for yourself and forgive others.
80190d1daSdanielk1977#    May you share freely, never taking more than you give.
90190d1daSdanielk1977#
100190d1daSdanielk1977#***********************************************************************
110190d1daSdanielk1977#
12aef0bf64Sdanielk1977# This file contains test cases focused on the two memory-management APIs,
13aef0bf64Sdanielk1977# sqlite3_soft_heap_limit() and sqlite3_release_memory().
14aef0bf64Sdanielk1977#
15*eee4c8caSdrh# $Id: malloc5.test,v 1.18 2008/02/18 22:24:58 drh Exp $
160190d1daSdanielk1977
170190d1daSdanielk1977#---------------------------------------------------------------------------
180190d1daSdanielk1977# NOTES ON EXPECTED BEHAVIOUR
190190d1daSdanielk1977#
200190d1daSdanielk1977#---------------------------------------------------------------------------
210190d1daSdanielk1977
2252622828Sdanielk1977
230190d1daSdanielk1977set testdir [file dirname $argv0]
240190d1daSdanielk1977source $testdir/tester.tcl
25*eee4c8caSdrhsource $testdir/malloc_common.tcl
2652622828Sdanielk1977db close
270190d1daSdanielk1977
28aef0bf64Sdanielk1977# Only run these tests if memory debugging is turned on.
29ed138fb3Sdrh#
30*eee4c8caSdrhif {!$MEMDEBUG} {
315a3032b3Sdrh   puts "Skipping malloc5 tests: not compiled with -DSQLITE_MEMDEBUG..."
32aef0bf64Sdanielk1977   finish_test
33aef0bf64Sdanielk1977   return
34aef0bf64Sdanielk1977}
35aef0bf64Sdanielk1977
3652622828Sdanielk1977# Skip these tests if OMIT_MEMORY_MANAGEMENT was defined at compile time.
3752622828Sdanielk1977ifcapable !memorymanage {
3852622828Sdanielk1977   finish_test
3952622828Sdanielk1977   return
4052622828Sdanielk1977}
4152622828Sdanielk1977
423aefabafSdrhsqlite3_soft_heap_limit 0
4352622828Sdanielk1977sqlite3 db test.db
4452622828Sdanielk1977
450190d1daSdanielk1977do_test malloc5-1.1 {
466aafc29bSdrh  # Simplest possible test. Call sqlite3_release_memory when there is exactly
470190d1daSdanielk1977  # one unused page in a single pager cache. This test case set's the
480190d1daSdanielk1977  # value of the ::pgalloc variable, which is used in subsequent tests.
490190d1daSdanielk1977  #
500190d1daSdanielk1977  # Note: Even though executing this statement on an empty database
510190d1daSdanielk1977  # modifies 2 pages (the root of sqlite_master and the new root page),
520190d1daSdanielk1977  # the sqlite_master root (page 1) is never freed because the btree layer
530190d1daSdanielk1977  # retains a reference to it for the entire transaction.
540190d1daSdanielk1977  execsql {
55271d8cb0Sdrh    PRAGMA auto_vacuum=OFF;
560190d1daSdanielk1977    BEGIN;
570190d1daSdanielk1977    CREATE TABLE abc(a, b, c);
580190d1daSdanielk1977  }
596aafc29bSdrh  set ::pgalloc [sqlite3_release_memory]
600190d1daSdanielk1977  expr $::pgalloc > 0
610190d1daSdanielk1977} {1}
620190d1daSdanielk1977do_test malloc5-1.2 {
630190d1daSdanielk1977  # Test that the transaction started in the above test is still active.
640190d1daSdanielk1977  # Because the page freed had been written to, freeing it required a
650190d1daSdanielk1977  # journal sync and exclusive lock on the database file. Test the file
660190d1daSdanielk1977  # appears to be locked.
670190d1daSdanielk1977  sqlite3 db2 test.db
680190d1daSdanielk1977  catchsql {
690190d1daSdanielk1977    SELECT * FROM abc;
700190d1daSdanielk1977  } db2
710190d1daSdanielk1977} {1 {database is locked}}
720190d1daSdanielk1977do_test malloc5-1.3 {
736aafc29bSdrh  # Again call [sqlite3_release_memory] when there is exactly one unused page
740190d1daSdanielk1977  # in the cache. The same amount of memory is required, but no journal-sync
750190d1daSdanielk1977  # or exclusive lock should be established.
760190d1daSdanielk1977  execsql {
770190d1daSdanielk1977    COMMIT;
780190d1daSdanielk1977    BEGIN;
790190d1daSdanielk1977    SELECT * FROM abc;
800190d1daSdanielk1977  }
816aafc29bSdrh  sqlite3_release_memory
820190d1daSdanielk1977} $::pgalloc
830190d1daSdanielk1977do_test malloc5-1.4 {
840190d1daSdanielk1977  # Database should not be locked this time.
850190d1daSdanielk1977  catchsql {
860190d1daSdanielk1977    SELECT * FROM abc;
870190d1daSdanielk1977  } db2
880190d1daSdanielk1977} {0 {}}
890190d1daSdanielk1977do_test malloc5-1.5 {
900190d1daSdanielk1977  # Manipulate the cache so that it contains two unused pages. One requires
910190d1daSdanielk1977  # a journal-sync to free, the other does not.
9224168728Sdanielk1977  db2 close
930190d1daSdanielk1977  execsql {
940190d1daSdanielk1977    SELECT * FROM abc;
950190d1daSdanielk1977    CREATE TABLE def(d, e, f);
960190d1daSdanielk1977  }
976aafc29bSdrh  sqlite3_release_memory 500
980190d1daSdanielk1977} $::pgalloc
990190d1daSdanielk1977do_test malloc5-1.6 {
1000190d1daSdanielk1977  # Database should not be locked this time. The above test case only
1010190d1daSdanielk1977  # requested 500 bytes of memory, which can be obtained by freeing the page
1020190d1daSdanielk1977  # that does not require an fsync().
10324168728Sdanielk1977  sqlite3 db2 test.db
1040190d1daSdanielk1977  catchsql {
1050190d1daSdanielk1977    SELECT * FROM abc;
1060190d1daSdanielk1977  } db2
1070190d1daSdanielk1977} {0 {}}
1080190d1daSdanielk1977do_test malloc5-1.7 {
1090190d1daSdanielk1977  # Release another 500 bytes of memory. This time we require a sync(),
1100190d1daSdanielk1977  # so the database file will be locked afterwards.
11124168728Sdanielk1977  db2 close
1126aafc29bSdrh  sqlite3_release_memory 500
1130190d1daSdanielk1977} $::pgalloc
1140190d1daSdanielk1977do_test malloc5-1.8 {
11524168728Sdanielk1977  sqlite3 db2 test.db
1160190d1daSdanielk1977  catchsql {
1170190d1daSdanielk1977    SELECT * FROM abc;
1180190d1daSdanielk1977  } db2
1190190d1daSdanielk1977} {1 {database is locked}}
1200190d1daSdanielk1977do_test malloc5-1.9 {
1210190d1daSdanielk1977  execsql {
1220190d1daSdanielk1977    COMMIT;
1230190d1daSdanielk1977  }
1240190d1daSdanielk1977} {}
1250190d1daSdanielk1977
1260190d1daSdanielk1977do_test malloc5-2.1 {
1270190d1daSdanielk1977  # Put some data in tables abc and def. Both tables are still wholly
1280190d1daSdanielk1977  # contained within their root pages.
1290190d1daSdanielk1977  execsql {
1300190d1daSdanielk1977    INSERT INTO abc VALUES(1, 2, 3);
1310190d1daSdanielk1977    INSERT INTO abc VALUES(4, 5, 6);
1320190d1daSdanielk1977    INSERT INTO def VALUES(7, 8, 9);
1330190d1daSdanielk1977    INSERT INTO def VALUES(10,11,12);
1340190d1daSdanielk1977  }
1350190d1daSdanielk1977} {}
1360190d1daSdanielk1977do_test malloc5-2.2 {
1370190d1daSdanielk1977  # Load the root-page for table def into the cache. Then query table abc.
1380190d1daSdanielk1977  # Halfway through the query call sqlite3_release_memory(). The goal of this
1390190d1daSdanielk1977  # test is to make sure we don't free pages that are in use (specifically,
1400190d1daSdanielk1977  # the root of table abc).
1410190d1daSdanielk1977  set nRelease 0
1420190d1daSdanielk1977  execsql {
1430190d1daSdanielk1977    BEGIN;
1440190d1daSdanielk1977    SELECT * FROM def;
1450190d1daSdanielk1977  }
1465591df55Sdanielk1977  set data [list]
1470190d1daSdanielk1977  db eval {SELECT * FROM abc} {
1486aafc29bSdrh    incr nRelease [sqlite3_release_memory]
1490190d1daSdanielk1977    lappend data $a $b $c
1500190d1daSdanielk1977  }
1515591df55Sdanielk1977  execsql {
1525591df55Sdanielk1977    COMMIT;
1535591df55Sdanielk1977  }
1540190d1daSdanielk1977  list $nRelease $data
1550190d1daSdanielk1977} [list $pgalloc [list 1 2 3 4 5 6]]
1560190d1daSdanielk1977
1575591df55Sdanielk1977do_test malloc5-3.1 {
1585591df55Sdanielk1977  # Simple test to show that if two pagers are opened from within this
1595591df55Sdanielk1977  # thread, memory is freed from both when sqlite3_release_memory() is
1605591df55Sdanielk1977  # called.
1615591df55Sdanielk1977  execsql {
1625591df55Sdanielk1977    BEGIN;
1635591df55Sdanielk1977    SELECT * FROM abc;
1645591df55Sdanielk1977  }
1655591df55Sdanielk1977  execsql {
1665591df55Sdanielk1977    SELECT * FROM sqlite_master;
1675591df55Sdanielk1977    BEGIN;
1685591df55Sdanielk1977    SELECT * FROM def;
1695591df55Sdanielk1977  } db2
1706aafc29bSdrh  sqlite3_release_memory
1715591df55Sdanielk1977} [expr $::pgalloc * 2]
1725591df55Sdanielk1977do_test malloc5-3.2 {
1735591df55Sdanielk1977  concat \
1745591df55Sdanielk1977    [execsql {SELECT * FROM abc; COMMIT}] \
1755591df55Sdanielk1977    [execsql {SELECT * FROM def; COMMIT} db2]
1765591df55Sdanielk1977} {1 2 3 4 5 6 7 8 9 10 11 12}
1775591df55Sdanielk1977
1785591df55Sdanielk1977db2 close
179ed138fb3Sdrhputs "Highwater mark: [sqlite3_memory_highwater]"
1805591df55Sdanielk1977
1815591df55Sdanielk1977# The following two test cases each execute a transaction in which
1825591df55Sdanielk1977# 10000 rows are inserted into table abc. The first test case is used
1835591df55Sdanielk1977# to ensure that more than 1MB of dynamic memory is used to perform
1845591df55Sdanielk1977# the transaction.
1855591df55Sdanielk1977#
1865591df55Sdanielk1977# The second test case sets the "soft-heap-limit" to 100,000 bytes (0.1 MB)
1875591df55Sdanielk1977# and tests to see that this limit is not exceeded at any point during
1885591df55Sdanielk1977# transaction execution.
1895591df55Sdanielk1977#
190aef0bf64Sdanielk1977# Before executing malloc5-4.* we save the value of the current soft heap
191aef0bf64Sdanielk1977# limit in variable ::soft_limit. The original value is restored after
192aef0bf64Sdanielk1977# running the tests.
193aef0bf64Sdanielk1977#
1946aafc29bSdrhset ::soft_limit [sqlite3_soft_heap_limit -1]
1953a7fb7c4Sdrhexecsql {PRAGMA cache_size=2000}
1965591df55Sdanielk1977do_test malloc5-4.1 {
1975591df55Sdanielk1977  execsql {BEGIN;}
1985591df55Sdanielk1977  execsql {DELETE FROM abc;}
1995591df55Sdanielk1977  for {set i 0} {$i < 10000} {incr i} {
2005591df55Sdanielk1977    execsql "INSERT INTO abc VALUES($i, $i, '[string repeat X 100]');"
2015591df55Sdanielk1977  }
2025591df55Sdanielk1977  execsql {COMMIT;}
203ed138fb3Sdrh  set nMaxBytes [sqlite3_memory_highwater 1]
204ed138fb3Sdrh  puts -nonewline " (Highwater mark: $nMaxBytes) "
205ed138fb3Sdrh  expr $nMaxBytes > 1000000
2065591df55Sdanielk1977} {1}
2075591df55Sdanielk1977do_test malloc5-4.2 {
2086aafc29bSdrh  sqlite3_release_memory
2096aafc29bSdrh  sqlite3_soft_heap_limit 100000
210ed138fb3Sdrh  sqlite3_memory_highwater 1
2115591df55Sdanielk1977  execsql {BEGIN;}
2125591df55Sdanielk1977  for {set i 0} {$i < 10000} {incr i} {
2135591df55Sdanielk1977    execsql "INSERT INTO abc VALUES($i, $i, '[string repeat X 100]');"
2145591df55Sdanielk1977  }
2155591df55Sdanielk1977  execsql {COMMIT;}
216ed138fb3Sdrh  set nMaxBytes [sqlite3_memory_highwater 1]
217ed138fb3Sdrh  puts -nonewline " (Highwater mark: $nMaxBytes) "
2188da6021bSdanielk1977
2198da6021bSdanielk1977  # We used to test ($nMaxBytes<100000), because the soft-heap-limit is
2208da6021bSdanielk1977  # 100000 bytes. But if an allocation that will exceed the
2218da6021bSdanielk1977  # soft-heap-limit is requested from within the only pager instance in
2228da6021bSdanielk1977  # the system, then there is no way to free memory and the limit has to
2238da6021bSdanielk1977  # be exceeded. An exception is memory allocated to store actual page
2248da6021bSdanielk1977  # data (the code contains a special case for this).
2258da6021bSdanielk1977  #
2268da6021bSdanielk1977  # This is not a problem because all allocations apart from those
2278da6021bSdanielk1977  # used to store cached page data are both small and transient.
2288da6021bSdanielk1977  #
2298da6021bSdanielk1977  # Summary: the actual high-water mark for memory usage may be slightly
2308da6021bSdanielk1977  # higher than the soft-heap-limit. The specific allocations that cause
2318da6021bSdanielk1977  # the problem are the calls to sqlite3_malloc() inserted into selected
2328da6021bSdanielk1977  # sqlite3OsXXX() functions in test builds.
2338da6021bSdanielk1977  #
2348da6021bSdanielk1977  expr $nMaxBytes <= 100100
2355591df55Sdanielk1977} {1}
2365591df55Sdanielk1977do_test malloc5-4.3 {
2375591df55Sdanielk1977  # Check that the content of table abc is at least roughly as expected.
2385591df55Sdanielk1977  execsql {
2395591df55Sdanielk1977    SELECT count(*), sum(a), sum(b) FROM abc;
2405591df55Sdanielk1977  }
2415591df55Sdanielk1977} [list 20000 [expr int(20000.0 * 4999.5)] [expr int(20000.0 * 4999.5)]]
2425591df55Sdanielk1977
243aef0bf64Sdanielk1977# Restore the soft heap limit.
2446aafc29bSdrhsqlite3_soft_heap_limit $::soft_limit
24552622828Sdanielk1977
246c551edc2Sdanielk1977# Test that there are no problems calling sqlite3_release_memory when
247c551edc2Sdanielk1977# there are open in-memory databases.
248c551edc2Sdanielk1977#
249c551edc2Sdanielk1977# At one point these tests would cause a seg-fault.
250c551edc2Sdanielk1977#
251c551edc2Sdanielk1977do_test malloc5-5.1 {
252c551edc2Sdanielk1977  db close
253c551edc2Sdanielk1977  sqlite3 db :memory:
254c551edc2Sdanielk1977  execsql {
255c551edc2Sdanielk1977    BEGIN;
256c551edc2Sdanielk1977    CREATE TABLE abc(a, b, c);
257c551edc2Sdanielk1977    INSERT INTO abc VALUES('abcdefghi', 1234567890, NULL);
258c551edc2Sdanielk1977    INSERT INTO abc SELECT * FROM abc;
259c551edc2Sdanielk1977    INSERT INTO abc SELECT * FROM abc;
260c551edc2Sdanielk1977    INSERT INTO abc SELECT * FROM abc;
261c551edc2Sdanielk1977    INSERT INTO abc SELECT * FROM abc;
262c551edc2Sdanielk1977    INSERT INTO abc SELECT * FROM abc;
263c551edc2Sdanielk1977    INSERT INTO abc SELECT * FROM abc;
264c551edc2Sdanielk1977    INSERT INTO abc SELECT * FROM abc;
265c551edc2Sdanielk1977  }
266c551edc2Sdanielk1977  sqlite3_release_memory
267c551edc2Sdanielk1977} 0
26884f786fcSdanielk1977do_test malloc5-5.2 {
269c551edc2Sdanielk1977  sqlite3_soft_heap_limit 5000
270c551edc2Sdanielk1977  execsql {
271c551edc2Sdanielk1977    COMMIT;
272c551edc2Sdanielk1977    PRAGMA temp_store = memory;
273c551edc2Sdanielk1977    SELECT * FROM abc ORDER BY a;
274c551edc2Sdanielk1977  }
275c551edc2Sdanielk1977  expr 1
276c551edc2Sdanielk1977} {1}
27784f786fcSdanielk1977sqlite3_soft_heap_limit $::soft_limit
27884f786fcSdanielk1977
27984f786fcSdanielk1977#-------------------------------------------------------------------------
28084f786fcSdanielk1977# The following test cases (malloc5-6.*) test the new global LRU list
28184f786fcSdanielk1977# used to determine the pages to recycle when sqlite3_release_memory is
28284f786fcSdanielk1977# called and there is more than one pager open.
28384f786fcSdanielk1977#
28484f786fcSdanielk1977proc nPage {db} {
28584f786fcSdanielk1977  set bt [btree_from_db $db]
28684f786fcSdanielk1977  array set stats [btree_pager_stats $bt]
28784f786fcSdanielk1977  set stats(page)
28884f786fcSdanielk1977}
28984f786fcSdanielk1977db close
29084f786fcSdanielk1977file delete -force test.db test.db-journal test2.db test2.db-journal
29184f786fcSdanielk1977
29284f786fcSdanielk1977# This block of test-cases (malloc5-6.1.*) prepares two database files
29384f786fcSdanielk1977# for the subsequent tests.
29484f786fcSdanielk1977do_test malloc5-6.1.1 {
29584f786fcSdanielk1977  sqlite3 db test.db
29684f786fcSdanielk1977  execsql {
29784f786fcSdanielk1977    PRAGMA page_size=1024;
29884f786fcSdanielk1977    PRAGMA default_cache_size=10;
29984f786fcSdanielk1977    BEGIN;
30084f786fcSdanielk1977    CREATE TABLE abc(a PRIMARY KEY, b, c);
30184f786fcSdanielk1977    INSERT INTO abc VALUES(randstr(50,50), randstr(75,75), randstr(100,100));
30284f786fcSdanielk1977    INSERT INTO abc
30384f786fcSdanielk1977        SELECT randstr(50,50), randstr(75,75), randstr(100,100) FROM abc;
30484f786fcSdanielk1977    INSERT INTO abc
30584f786fcSdanielk1977        SELECT randstr(50,50), randstr(75,75), randstr(100,100) FROM abc;
30684f786fcSdanielk1977    INSERT INTO abc
30784f786fcSdanielk1977        SELECT randstr(50,50), randstr(75,75), randstr(100,100) FROM abc;
30884f786fcSdanielk1977    INSERT INTO abc
30984f786fcSdanielk1977        SELECT randstr(50,50), randstr(75,75), randstr(100,100) FROM abc;
31084f786fcSdanielk1977    INSERT INTO abc
31184f786fcSdanielk1977        SELECT randstr(50,50), randstr(75,75), randstr(100,100) FROM abc;
31284f786fcSdanielk1977    INSERT INTO abc
31384f786fcSdanielk1977        SELECT randstr(50,50), randstr(75,75), randstr(100,100) FROM abc;
31484f786fcSdanielk1977    COMMIT;
31584f786fcSdanielk1977  }
31684f786fcSdanielk1977  copy_file test.db test2.db
31784f786fcSdanielk1977  sqlite3 db2 test2.db
318fa18beceSdanielk1977  list \
319fa18beceSdanielk1977    [expr ([file size test.db]/1024)>20] [expr ([file size test2.db]/1024)>20]
320fa18beceSdanielk1977} {1 1}
32184f786fcSdanielk1977do_test malloc5-6.1.2 {
32284f786fcSdanielk1977  list [execsql {PRAGMA cache_size}] [execsql {PRAGMA cache_size} db2]
32384f786fcSdanielk1977} {10 10}
32484f786fcSdanielk1977
32584f786fcSdanielk1977do_test malloc5-6.2.1 {
32684f786fcSdanielk1977  execsql { SELECT * FROM abc } db2
32784f786fcSdanielk1977  execsql {SELECT * FROM abc} db
32884f786fcSdanielk1977  list [nPage db] [nPage db2]
32984f786fcSdanielk1977} {10 10}
33084f786fcSdanielk1977do_test malloc5-6.2.2 {
33184f786fcSdanielk1977  # If we now try to reclaim some memory, it should come from the db2 cache.
33284f786fcSdanielk1977  sqlite3_release_memory 3000
33384f786fcSdanielk1977  list [nPage db] [nPage db2]
33484f786fcSdanielk1977} {10 7}
33584f786fcSdanielk1977do_test malloc5-6.2.3 {
33684f786fcSdanielk1977  # Access the db2 cache again, so that all the db2 pages have been used
33784f786fcSdanielk1977  # more recently than all the db pages. Then try to reclaim 3000 bytes.
33884f786fcSdanielk1977  # This time, 3 pages should be pulled from the db cache.
33984f786fcSdanielk1977  execsql { SELECT * FROM abc } db2
34084f786fcSdanielk1977  sqlite3_release_memory 3000
34184f786fcSdanielk1977  list [nPage db] [nPage db2]
34284f786fcSdanielk1977} {7 10}
34384f786fcSdanielk1977
34484f786fcSdanielk1977
34584f786fcSdanielk1977do_test malloc5-6.3.1 {
34684f786fcSdanielk1977  # Now open a transaction and update 2 pages in the db2 cache. Then
34784f786fcSdanielk1977  # do a SELECT on the db cache so that all the db pages are more recently
34884f786fcSdanielk1977  # used than the db2 pages. When we try to free memory, SQLite should
34984f786fcSdanielk1977  # free the non-dirty db2 pages, then the db pages, then finally use
35084f786fcSdanielk1977  # sync() to free up the dirty db2 pages. The only page that cannot be
35184f786fcSdanielk1977  # freed is page1 of db2. Because there is an open transaction, the
35284f786fcSdanielk1977  # btree layer holds a reference to page 1 in the db2 cache.
35384f786fcSdanielk1977  execsql {
35484f786fcSdanielk1977    BEGIN;
35584f786fcSdanielk1977    UPDATE abc SET c = randstr(100,100)
35684f786fcSdanielk1977    WHERE rowid = 1 OR rowid = (SELECT max(rowid) FROM abc);
35784f786fcSdanielk1977  } db2
35884f786fcSdanielk1977  execsql { SELECT * FROM abc } db
35984f786fcSdanielk1977  list [nPage db] [nPage db2]
36084f786fcSdanielk1977} {10 10}
36184f786fcSdanielk1977do_test malloc5-6.3.2 {
36284f786fcSdanielk1977  # Try to release 7700 bytes. This should release all the
36384f786fcSdanielk1977  # non-dirty pages held by db2.
36484f786fcSdanielk1977  sqlite3_release_memory [expr 7*1100]
36584f786fcSdanielk1977  list [nPage db] [nPage db2]
36684f786fcSdanielk1977} {10 3}
36784f786fcSdanielk1977do_test malloc5-6.3.3 {
36884f786fcSdanielk1977  # Try to release another 1000 bytes. This should come fromt the db
36984f786fcSdanielk1977  # cache, since all three pages held by db2 are either in-use or diry.
37084f786fcSdanielk1977  sqlite3_release_memory 1000
37184f786fcSdanielk1977  list [nPage db] [nPage db2]
37284f786fcSdanielk1977} {9 3}
37384f786fcSdanielk1977do_test malloc5-6.3.4 {
37484f786fcSdanielk1977  # Now release 9900 more (about 9 pages worth). This should expunge
37584f786fcSdanielk1977  # the rest of the db cache. But the db2 cache remains intact, because
37684f786fcSdanielk1977  # SQLite tries to avoid calling sync().
37784f786fcSdanielk1977  sqlite3_release_memory 9900
37884f786fcSdanielk1977  list [nPage db] [nPage db2]
37984f786fcSdanielk1977} {0 3}
38084f786fcSdanielk1977do_test malloc5-6.3.5 {
38184f786fcSdanielk1977  # But if we are really insistent, SQLite will consent to call sync()
38284f786fcSdanielk1977  # if there is no other option.
38384f786fcSdanielk1977  sqlite3_release_memory 1000
38484f786fcSdanielk1977  list [nPage db] [nPage db2]
38584f786fcSdanielk1977} {0 2}
38684f786fcSdanielk1977do_test malloc5-6.3.6 {
38784f786fcSdanielk1977  # The referenced page (page 1 of the db2 cache) will not be freed no
38884f786fcSdanielk1977  # matter how much memory we ask for:
38984f786fcSdanielk1977  sqlite3_release_memory 31459
39084f786fcSdanielk1977  list [nPage db] [nPage db2]
39184f786fcSdanielk1977} {0 1}
39284f786fcSdanielk1977
39384f786fcSdanielk1977db2 close
394c551edc2Sdanielk1977
395c551edc2Sdanielk1977sqlite3_soft_heap_limit $::soft_limit
396c551edc2Sdanielk1977finish_test
39752622828Sdanielk1977catch {db close}
398