danielk1977 | 0190d1d | 2005-12-19 14:18:11 +0000 | [diff] [blame] | 1 | # 2005 November 30 |
| 2 | # |
| 3 | # The author disclaims copyright to this source code. In place of |
| 4 | # a legal notice, here is a blessing: |
| 5 | # |
| 6 | # May you do good and not evil. |
| 7 | # May you find forgiveness for yourself and forgive others. |
| 8 | # May you share freely, never taking more than you give. |
| 9 | # |
| 10 | #*********************************************************************** |
| 11 | # |
danielk1977 | aef0bf6 | 2005-12-30 16:28:01 +0000 | [diff] [blame] | 12 | # This file contains test cases focused on the two memory-management APIs, |
| 13 | # sqlite3_soft_heap_limit() and sqlite3_release_memory(). |
| 14 | # |
drh | eee4c8c | 2008-02-18 22:24:57 +0000 | [diff] [blame^] | 15 | # $Id: malloc5.test,v 1.18 2008/02/18 22:24:58 drh Exp $ |
danielk1977 | 0190d1d | 2005-12-19 14:18:11 +0000 | [diff] [blame] | 16 | |
| 17 | #--------------------------------------------------------------------------- |
| 18 | # NOTES ON EXPECTED BEHAVIOUR |
| 19 | # |
| 20 | #--------------------------------------------------------------------------- |
| 21 | |
danielk1977 | 5262282 | 2006-01-09 09:59:49 +0000 | [diff] [blame] | 22 | |
danielk1977 | 0190d1d | 2005-12-19 14:18:11 +0000 | [diff] [blame] | 23 | set testdir [file dirname $argv0] |
| 24 | source $testdir/tester.tcl |
drh | eee4c8c | 2008-02-18 22:24:57 +0000 | [diff] [blame^] | 25 | source $testdir/malloc_common.tcl |
danielk1977 | 5262282 | 2006-01-09 09:59:49 +0000 | [diff] [blame] | 26 | db close |
danielk1977 | 0190d1d | 2005-12-19 14:18:11 +0000 | [diff] [blame] | 27 | |
danielk1977 | aef0bf6 | 2005-12-30 16:28:01 +0000 | [diff] [blame] | 28 | # Only run these tests if memory debugging is turned on. |
drh | ed138fb | 2007-08-22 22:04:37 +0000 | [diff] [blame] | 29 | # |
drh | eee4c8c | 2008-02-18 22:24:57 +0000 | [diff] [blame^] | 30 | if {!$MEMDEBUG} { |
drh | 5a3032b | 2007-09-03 16:12:09 +0000 | [diff] [blame] | 31 | puts "Skipping malloc5 tests: not compiled with -DSQLITE_MEMDEBUG..." |
danielk1977 | aef0bf6 | 2005-12-30 16:28:01 +0000 | [diff] [blame] | 32 | finish_test |
| 33 | return |
| 34 | } |
| 35 | |
danielk1977 | 5262282 | 2006-01-09 09:59:49 +0000 | [diff] [blame] | 36 | # Skip these tests if OMIT_MEMORY_MANAGEMENT was defined at compile time. |
| 37 | ifcapable !memorymanage { |
| 38 | finish_test |
| 39 | return |
| 40 | } |
| 41 | |
drh | 3aefaba | 2007-08-12 20:07:58 +0000 | [diff] [blame] | 42 | sqlite3_soft_heap_limit 0 |
danielk1977 | 5262282 | 2006-01-09 09:59:49 +0000 | [diff] [blame] | 43 | sqlite3 db test.db |
| 44 | |
danielk1977 | 0190d1d | 2005-12-19 14:18:11 +0000 | [diff] [blame] | 45 | do_test malloc5-1.1 { |
drh | 6aafc29 | 2006-01-05 15:50:06 +0000 | [diff] [blame] | 46 | # Simplest possible test. Call sqlite3_release_memory when there is exactly |
danielk1977 | 0190d1d | 2005-12-19 14:18:11 +0000 | [diff] [blame] | 47 | # one unused page in a single pager cache. This test case set's the |
| 48 | # value of the ::pgalloc variable, which is used in subsequent tests. |
| 49 | # |
| 50 | # Note: Even though executing this statement on an empty database |
| 51 | # modifies 2 pages (the root of sqlite_master and the new root page), |
| 52 | # the sqlite_master root (page 1) is never freed because the btree layer |
| 53 | # retains a reference to it for the entire transaction. |
| 54 | execsql { |
drh | 271d8cb | 2007-04-07 17:44:27 +0000 | [diff] [blame] | 55 | PRAGMA auto_vacuum=OFF; |
danielk1977 | 0190d1d | 2005-12-19 14:18:11 +0000 | [diff] [blame] | 56 | BEGIN; |
| 57 | CREATE TABLE abc(a, b, c); |
| 58 | } |
drh | 6aafc29 | 2006-01-05 15:50:06 +0000 | [diff] [blame] | 59 | set ::pgalloc [sqlite3_release_memory] |
danielk1977 | 0190d1d | 2005-12-19 14:18:11 +0000 | [diff] [blame] | 60 | expr $::pgalloc > 0 |
| 61 | } {1} |
| 62 | do_test malloc5-1.2 { |
| 63 | # Test that the transaction started in the above test is still active. |
| 64 | # Because the page freed had been written to, freeing it required a |
| 65 | # journal sync and exclusive lock on the database file. Test the file |
| 66 | # appears to be locked. |
| 67 | sqlite3 db2 test.db |
| 68 | catchsql { |
| 69 | SELECT * FROM abc; |
| 70 | } db2 |
| 71 | } {1 {database is locked}} |
| 72 | do_test malloc5-1.3 { |
drh | 6aafc29 | 2006-01-05 15:50:06 +0000 | [diff] [blame] | 73 | # Again call [sqlite3_release_memory] when there is exactly one unused page |
danielk1977 | 0190d1d | 2005-12-19 14:18:11 +0000 | [diff] [blame] | 74 | # in the cache. The same amount of memory is required, but no journal-sync |
| 75 | # or exclusive lock should be established. |
| 76 | execsql { |
| 77 | COMMIT; |
| 78 | BEGIN; |
| 79 | SELECT * FROM abc; |
| 80 | } |
drh | 6aafc29 | 2006-01-05 15:50:06 +0000 | [diff] [blame] | 81 | sqlite3_release_memory |
danielk1977 | 0190d1d | 2005-12-19 14:18:11 +0000 | [diff] [blame] | 82 | } $::pgalloc |
| 83 | do_test malloc5-1.4 { |
| 84 | # Database should not be locked this time. |
| 85 | catchsql { |
| 86 | SELECT * FROM abc; |
| 87 | } db2 |
| 88 | } {0 {}} |
| 89 | do_test malloc5-1.5 { |
| 90 | # Manipulate the cache so that it contains two unused pages. One requires |
| 91 | # a journal-sync to free, the other does not. |
danielk1977 | 2416872 | 2007-04-02 05:07:47 +0000 | [diff] [blame] | 92 | db2 close |
danielk1977 | 0190d1d | 2005-12-19 14:18:11 +0000 | [diff] [blame] | 93 | execsql { |
| 94 | SELECT * FROM abc; |
| 95 | CREATE TABLE def(d, e, f); |
| 96 | } |
drh | 6aafc29 | 2006-01-05 15:50:06 +0000 | [diff] [blame] | 97 | sqlite3_release_memory 500 |
danielk1977 | 0190d1d | 2005-12-19 14:18:11 +0000 | [diff] [blame] | 98 | } $::pgalloc |
| 99 | do_test malloc5-1.6 { |
| 100 | # Database should not be locked this time. The above test case only |
| 101 | # requested 500 bytes of memory, which can be obtained by freeing the page |
| 102 | # that does not require an fsync(). |
danielk1977 | 2416872 | 2007-04-02 05:07:47 +0000 | [diff] [blame] | 103 | sqlite3 db2 test.db |
danielk1977 | 0190d1d | 2005-12-19 14:18:11 +0000 | [diff] [blame] | 104 | catchsql { |
| 105 | SELECT * FROM abc; |
| 106 | } db2 |
| 107 | } {0 {}} |
| 108 | do_test malloc5-1.7 { |
| 109 | # Release another 500 bytes of memory. This time we require a sync(), |
| 110 | # so the database file will be locked afterwards. |
danielk1977 | 2416872 | 2007-04-02 05:07:47 +0000 | [diff] [blame] | 111 | db2 close |
drh | 6aafc29 | 2006-01-05 15:50:06 +0000 | [diff] [blame] | 112 | sqlite3_release_memory 500 |
danielk1977 | 0190d1d | 2005-12-19 14:18:11 +0000 | [diff] [blame] | 113 | } $::pgalloc |
| 114 | do_test malloc5-1.8 { |
danielk1977 | 2416872 | 2007-04-02 05:07:47 +0000 | [diff] [blame] | 115 | sqlite3 db2 test.db |
danielk1977 | 0190d1d | 2005-12-19 14:18:11 +0000 | [diff] [blame] | 116 | catchsql { |
| 117 | SELECT * FROM abc; |
| 118 | } db2 |
| 119 | } {1 {database is locked}} |
| 120 | do_test malloc5-1.9 { |
| 121 | execsql { |
| 122 | COMMIT; |
| 123 | } |
| 124 | } {} |
| 125 | |
danielk1977 | 0190d1d | 2005-12-19 14:18:11 +0000 | [diff] [blame] | 126 | do_test malloc5-2.1 { |
| 127 | # Put some data in tables abc and def. Both tables are still wholly |
| 128 | # contained within their root pages. |
| 129 | execsql { |
| 130 | INSERT INTO abc VALUES(1, 2, 3); |
| 131 | INSERT INTO abc VALUES(4, 5, 6); |
| 132 | INSERT INTO def VALUES(7, 8, 9); |
| 133 | INSERT INTO def VALUES(10,11,12); |
| 134 | } |
| 135 | } {} |
| 136 | do_test malloc5-2.2 { |
| 137 | # Load the root-page for table def into the cache. Then query table abc. |
| 138 | # Halfway through the query call sqlite3_release_memory(). The goal of this |
| 139 | # test is to make sure we don't free pages that are in use (specifically, |
| 140 | # the root of table abc). |
| 141 | set nRelease 0 |
| 142 | execsql { |
| 143 | BEGIN; |
| 144 | SELECT * FROM def; |
| 145 | } |
danielk1977 | 5591df5 | 2005-12-20 09:19:37 +0000 | [diff] [blame] | 146 | set data [list] |
danielk1977 | 0190d1d | 2005-12-19 14:18:11 +0000 | [diff] [blame] | 147 | db eval {SELECT * FROM abc} { |
drh | 6aafc29 | 2006-01-05 15:50:06 +0000 | [diff] [blame] | 148 | incr nRelease [sqlite3_release_memory] |
danielk1977 | 0190d1d | 2005-12-19 14:18:11 +0000 | [diff] [blame] | 149 | lappend data $a $b $c |
| 150 | } |
danielk1977 | 5591df5 | 2005-12-20 09:19:37 +0000 | [diff] [blame] | 151 | execsql { |
| 152 | COMMIT; |
| 153 | } |
danielk1977 | 0190d1d | 2005-12-19 14:18:11 +0000 | [diff] [blame] | 154 | list $nRelease $data |
| 155 | } [list $pgalloc [list 1 2 3 4 5 6]] |
| 156 | |
danielk1977 | 5591df5 | 2005-12-20 09:19:37 +0000 | [diff] [blame] | 157 | do_test malloc5-3.1 { |
| 158 | # Simple test to show that if two pagers are opened from within this |
| 159 | # thread, memory is freed from both when sqlite3_release_memory() is |
| 160 | # called. |
| 161 | execsql { |
| 162 | BEGIN; |
| 163 | SELECT * FROM abc; |
| 164 | } |
| 165 | execsql { |
| 166 | SELECT * FROM sqlite_master; |
| 167 | BEGIN; |
| 168 | SELECT * FROM def; |
| 169 | } db2 |
drh | 6aafc29 | 2006-01-05 15:50:06 +0000 | [diff] [blame] | 170 | sqlite3_release_memory |
danielk1977 | 5591df5 | 2005-12-20 09:19:37 +0000 | [diff] [blame] | 171 | } [expr $::pgalloc * 2] |
| 172 | do_test malloc5-3.2 { |
| 173 | concat \ |
| 174 | [execsql {SELECT * FROM abc; COMMIT}] \ |
| 175 | [execsql {SELECT * FROM def; COMMIT} db2] |
| 176 | } {1 2 3 4 5 6 7 8 9 10 11 12} |
| 177 | |
| 178 | db2 close |
drh | ed138fb | 2007-08-22 22:04:37 +0000 | [diff] [blame] | 179 | puts "Highwater mark: [sqlite3_memory_highwater]" |
danielk1977 | 5591df5 | 2005-12-20 09:19:37 +0000 | [diff] [blame] | 180 | |
| 181 | # The following two test cases each execute a transaction in which |
| 182 | # 10000 rows are inserted into table abc. The first test case is used |
| 183 | # to ensure that more than 1MB of dynamic memory is used to perform |
| 184 | # the transaction. |
| 185 | # |
| 186 | # The second test case sets the "soft-heap-limit" to 100,000 bytes (0.1 MB) |
| 187 | # and tests to see that this limit is not exceeded at any point during |
| 188 | # transaction execution. |
| 189 | # |
danielk1977 | aef0bf6 | 2005-12-30 16:28:01 +0000 | [diff] [blame] | 190 | # Before executing malloc5-4.* we save the value of the current soft heap |
| 191 | # limit in variable ::soft_limit. The original value is restored after |
| 192 | # running the tests. |
| 193 | # |
drh | 6aafc29 | 2006-01-05 15:50:06 +0000 | [diff] [blame] | 194 | set ::soft_limit [sqlite3_soft_heap_limit -1] |
drh | 3a7fb7c | 2007-08-10 16:41:08 +0000 | [diff] [blame] | 195 | execsql {PRAGMA cache_size=2000} |
danielk1977 | 5591df5 | 2005-12-20 09:19:37 +0000 | [diff] [blame] | 196 | do_test malloc5-4.1 { |
| 197 | execsql {BEGIN;} |
| 198 | execsql {DELETE FROM abc;} |
| 199 | for {set i 0} {$i < 10000} {incr i} { |
| 200 | execsql "INSERT INTO abc VALUES($i, $i, '[string repeat X 100]');" |
| 201 | } |
| 202 | execsql {COMMIT;} |
drh | ed138fb | 2007-08-22 22:04:37 +0000 | [diff] [blame] | 203 | set nMaxBytes [sqlite3_memory_highwater 1] |
| 204 | puts -nonewline " (Highwater mark: $nMaxBytes) " |
| 205 | expr $nMaxBytes > 1000000 |
danielk1977 | 5591df5 | 2005-12-20 09:19:37 +0000 | [diff] [blame] | 206 | } {1} |
| 207 | do_test malloc5-4.2 { |
drh | 6aafc29 | 2006-01-05 15:50:06 +0000 | [diff] [blame] | 208 | sqlite3_release_memory |
drh | 6aafc29 | 2006-01-05 15:50:06 +0000 | [diff] [blame] | 209 | sqlite3_soft_heap_limit 100000 |
drh | ed138fb | 2007-08-22 22:04:37 +0000 | [diff] [blame] | 210 | sqlite3_memory_highwater 1 |
danielk1977 | 5591df5 | 2005-12-20 09:19:37 +0000 | [diff] [blame] | 211 | execsql {BEGIN;} |
| 212 | for {set i 0} {$i < 10000} {incr i} { |
| 213 | execsql "INSERT INTO abc VALUES($i, $i, '[string repeat X 100]');" |
| 214 | } |
| 215 | execsql {COMMIT;} |
drh | ed138fb | 2007-08-22 22:04:37 +0000 | [diff] [blame] | 216 | set nMaxBytes [sqlite3_memory_highwater 1] |
| 217 | puts -nonewline " (Highwater mark: $nMaxBytes) " |
danielk1977 | 8da6021 | 2007-10-03 09:43:54 +0000 | [diff] [blame] | 218 | |
| 219 | # We used to test ($nMaxBytes<100000), because the soft-heap-limit is |
| 220 | # 100000 bytes. But if an allocation that will exceed the |
| 221 | # soft-heap-limit is requested from within the only pager instance in |
| 222 | # the system, then there is no way to free memory and the limit has to |
| 223 | # be exceeded. An exception is memory allocated to store actual page |
| 224 | # data (the code contains a special case for this). |
| 225 | # |
| 226 | # This is not a problem because all allocations apart from those |
| 227 | # used to store cached page data are both small and transient. |
| 228 | # |
| 229 | # Summary: the actual high-water mark for memory usage may be slightly |
| 230 | # higher than the soft-heap-limit. The specific allocations that cause |
| 231 | # the problem are the calls to sqlite3_malloc() inserted into selected |
| 232 | # sqlite3OsXXX() functions in test builds. |
| 233 | # |
| 234 | expr $nMaxBytes <= 100100 |
danielk1977 | 5591df5 | 2005-12-20 09:19:37 +0000 | [diff] [blame] | 235 | } {1} |
| 236 | do_test malloc5-4.3 { |
| 237 | # Check that the content of table abc is at least roughly as expected. |
| 238 | execsql { |
| 239 | SELECT count(*), sum(a), sum(b) FROM abc; |
| 240 | } |
| 241 | } [list 20000 [expr int(20000.0 * 4999.5)] [expr int(20000.0 * 4999.5)]] |
| 242 | |
danielk1977 | aef0bf6 | 2005-12-30 16:28:01 +0000 | [diff] [blame] | 243 | # Restore the soft heap limit. |
drh | 6aafc29 | 2006-01-05 15:50:06 +0000 | [diff] [blame] | 244 | sqlite3_soft_heap_limit $::soft_limit |
danielk1977 | 5262282 | 2006-01-09 09:59:49 +0000 | [diff] [blame] | 245 | |
danielk1977 | c551edc | 2007-04-05 13:12:13 +0000 | [diff] [blame] | 246 | # Test that there are no problems calling sqlite3_release_memory when |
| 247 | # there are open in-memory databases. |
| 248 | # |
| 249 | # At one point these tests would cause a seg-fault. |
| 250 | # |
| 251 | do_test malloc5-5.1 { |
| 252 | db close |
| 253 | sqlite3 db :memory: |
| 254 | execsql { |
| 255 | BEGIN; |
| 256 | CREATE TABLE abc(a, b, c); |
| 257 | INSERT INTO abc VALUES('abcdefghi', 1234567890, NULL); |
| 258 | INSERT INTO abc SELECT * FROM abc; |
| 259 | INSERT INTO abc SELECT * FROM abc; |
| 260 | INSERT INTO abc SELECT * FROM abc; |
| 261 | INSERT INTO abc SELECT * FROM abc; |
| 262 | INSERT INTO abc SELECT * FROM abc; |
| 263 | INSERT INTO abc SELECT * FROM abc; |
| 264 | INSERT INTO abc SELECT * FROM abc; |
| 265 | } |
| 266 | sqlite3_release_memory |
| 267 | } 0 |
danielk1977 | 84f786f | 2007-08-28 08:00:17 +0000 | [diff] [blame] | 268 | do_test malloc5-5.2 { |
danielk1977 | c551edc | 2007-04-05 13:12:13 +0000 | [diff] [blame] | 269 | sqlite3_soft_heap_limit 5000 |
| 270 | execsql { |
| 271 | COMMIT; |
| 272 | PRAGMA temp_store = memory; |
| 273 | SELECT * FROM abc ORDER BY a; |
| 274 | } |
| 275 | expr 1 |
| 276 | } {1} |
danielk1977 | 84f786f | 2007-08-28 08:00:17 +0000 | [diff] [blame] | 277 | sqlite3_soft_heap_limit $::soft_limit |
| 278 | |
| 279 | #------------------------------------------------------------------------- |
| 280 | # The following test cases (malloc5-6.*) test the new global LRU list |
| 281 | # used to determine the pages to recycle when sqlite3_release_memory is |
| 282 | # called and there is more than one pager open. |
| 283 | # |
| 284 | proc nPage {db} { |
| 285 | set bt [btree_from_db $db] |
| 286 | array set stats [btree_pager_stats $bt] |
| 287 | set stats(page) |
| 288 | } |
| 289 | db close |
| 290 | file delete -force test.db test.db-journal test2.db test2.db-journal |
| 291 | |
| 292 | # This block of test-cases (malloc5-6.1.*) prepares two database files |
| 293 | # for the subsequent tests. |
| 294 | do_test malloc5-6.1.1 { |
| 295 | sqlite3 db test.db |
| 296 | execsql { |
| 297 | PRAGMA page_size=1024; |
| 298 | PRAGMA default_cache_size=10; |
| 299 | BEGIN; |
| 300 | CREATE TABLE abc(a PRIMARY KEY, b, c); |
| 301 | INSERT INTO abc VALUES(randstr(50,50), randstr(75,75), randstr(100,100)); |
| 302 | INSERT INTO abc |
| 303 | SELECT randstr(50,50), randstr(75,75), randstr(100,100) FROM abc; |
| 304 | INSERT INTO abc |
| 305 | SELECT randstr(50,50), randstr(75,75), randstr(100,100) FROM abc; |
| 306 | INSERT INTO abc |
| 307 | SELECT randstr(50,50), randstr(75,75), randstr(100,100) FROM abc; |
| 308 | INSERT INTO abc |
| 309 | SELECT randstr(50,50), randstr(75,75), randstr(100,100) FROM abc; |
| 310 | INSERT INTO abc |
| 311 | SELECT randstr(50,50), randstr(75,75), randstr(100,100) FROM abc; |
| 312 | INSERT INTO abc |
| 313 | SELECT randstr(50,50), randstr(75,75), randstr(100,100) FROM abc; |
| 314 | COMMIT; |
| 315 | } |
| 316 | copy_file test.db test2.db |
| 317 | sqlite3 db2 test2.db |
danielk1977 | fa18bec | 2007-09-03 11:04:22 +0000 | [diff] [blame] | 318 | list \ |
| 319 | [expr ([file size test.db]/1024)>20] [expr ([file size test2.db]/1024)>20] |
| 320 | } {1 1} |
danielk1977 | 84f786f | 2007-08-28 08:00:17 +0000 | [diff] [blame] | 321 | do_test malloc5-6.1.2 { |
| 322 | list [execsql {PRAGMA cache_size}] [execsql {PRAGMA cache_size} db2] |
| 323 | } {10 10} |
| 324 | |
| 325 | do_test malloc5-6.2.1 { |
| 326 | execsql { SELECT * FROM abc } db2 |
| 327 | execsql {SELECT * FROM abc} db |
| 328 | list [nPage db] [nPage db2] |
| 329 | } {10 10} |
| 330 | do_test malloc5-6.2.2 { |
| 331 | # If we now try to reclaim some memory, it should come from the db2 cache. |
| 332 | sqlite3_release_memory 3000 |
| 333 | list [nPage db] [nPage db2] |
| 334 | } {10 7} |
| 335 | do_test malloc5-6.2.3 { |
| 336 | # Access the db2 cache again, so that all the db2 pages have been used |
| 337 | # more recently than all the db pages. Then try to reclaim 3000 bytes. |
| 338 | # This time, 3 pages should be pulled from the db cache. |
| 339 | execsql { SELECT * FROM abc } db2 |
| 340 | sqlite3_release_memory 3000 |
| 341 | list [nPage db] [nPage db2] |
| 342 | } {7 10} |
| 343 | |
| 344 | |
| 345 | do_test malloc5-6.3.1 { |
| 346 | # Now open a transaction and update 2 pages in the db2 cache. Then |
| 347 | # do a SELECT on the db cache so that all the db pages are more recently |
| 348 | # used than the db2 pages. When we try to free memory, SQLite should |
| 349 | # free the non-dirty db2 pages, then the db pages, then finally use |
| 350 | # sync() to free up the dirty db2 pages. The only page that cannot be |
| 351 | # freed is page1 of db2. Because there is an open transaction, the |
| 352 | # btree layer holds a reference to page 1 in the db2 cache. |
| 353 | execsql { |
| 354 | BEGIN; |
| 355 | UPDATE abc SET c = randstr(100,100) |
| 356 | WHERE rowid = 1 OR rowid = (SELECT max(rowid) FROM abc); |
| 357 | } db2 |
| 358 | execsql { SELECT * FROM abc } db |
| 359 | list [nPage db] [nPage db2] |
| 360 | } {10 10} |
| 361 | do_test malloc5-6.3.2 { |
| 362 | # Try to release 7700 bytes. This should release all the |
| 363 | # non-dirty pages held by db2. |
| 364 | sqlite3_release_memory [expr 7*1100] |
| 365 | list [nPage db] [nPage db2] |
| 366 | } {10 3} |
| 367 | do_test malloc5-6.3.3 { |
| 368 | # Try to release another 1000 bytes. This should come fromt the db |
| 369 | # cache, since all three pages held by db2 are either in-use or diry. |
| 370 | sqlite3_release_memory 1000 |
| 371 | list [nPage db] [nPage db2] |
| 372 | } {9 3} |
| 373 | do_test malloc5-6.3.4 { |
| 374 | # Now release 9900 more (about 9 pages worth). This should expunge |
| 375 | # the rest of the db cache. But the db2 cache remains intact, because |
| 376 | # SQLite tries to avoid calling sync(). |
| 377 | sqlite3_release_memory 9900 |
| 378 | list [nPage db] [nPage db2] |
| 379 | } {0 3} |
| 380 | do_test malloc5-6.3.5 { |
| 381 | # But if we are really insistent, SQLite will consent to call sync() |
| 382 | # if there is no other option. |
| 383 | sqlite3_release_memory 1000 |
| 384 | list [nPage db] [nPage db2] |
| 385 | } {0 2} |
| 386 | do_test malloc5-6.3.6 { |
| 387 | # The referenced page (page 1 of the db2 cache) will not be freed no |
| 388 | # matter how much memory we ask for: |
| 389 | sqlite3_release_memory 31459 |
| 390 | list [nPage db] [nPage db2] |
| 391 | } {0 1} |
| 392 | |
| 393 | db2 close |
danielk1977 | c551edc | 2007-04-05 13:12:13 +0000 | [diff] [blame] | 394 | |
| 395 | sqlite3_soft_heap_limit $::soft_limit |
| 396 | finish_test |
danielk1977 | 5262282 | 2006-01-09 09:59:49 +0000 | [diff] [blame] | 397 | catch {db close} |