000001 # 2011 November 16 000002 # 000003 # The author disclaims copyright to this source code. In place of 000004 # a legal notice, here is a blessing: 000005 # 000006 # May you do good and not evil. 000007 # May you find forgiveness for yourself and forgive others. 000008 # May you share freely, never taking more than you give. 000009 # 000010 #*********************************************************************** 000011 # 000012 # This file contains test cases for sqlite3_db_release_memory and 000013 # the PRAGMA shrink_memory statement. 000014 # 000015 000016 set testdir [file dirname $argv0] 000017 source $testdir/tester.tcl 000018 test_set_config_pagecache 0 0 000019 000020 if {[sqlite3_memory_used]==0} { 000021 # SQLITE_DEFAULT_MEMSTATUS=0 build. 000022 finish_test 000023 return 000024 } 000025 000026 000027 unset -nocomplain baseline 000028 do_test shrink-1.1 { 000029 db eval { 000030 PRAGMA cache_size = 2000; 000031 CREATE TABLE t1(x,y); 000032 INSERT INTO t1 VALUES(randomblob(1000000),1); 000033 } 000034 set ::baseline [sqlite3_memory_used] 000035 # EVIDENCE-OF: R-58814-63508 The sqlite3_db_release_memory(D) interface 000036 # attempts to free as much heap memory as possible from database 000037 # connection D. 000038 sqlite3_db_release_memory db 000039 expr {$::baseline > [sqlite3_memory_used]+500000} 000040 } {1} 000041 do_test shrink-1.2 { 000042 set baseline [sqlite3_memory_used] 000043 db eval { 000044 UPDATE t1 SET y=y+1; 000045 } 000046 expr {$::baseline+500000 < [sqlite3_memory_used]} 000047 } {1} 000048 do_test shrink-1.3 { 000049 set baseline [sqlite3_memory_used] 000050 db eval {PRAGMA shrink_memory} 000051 expr {$::baseline > [sqlite3_memory_used]+500000} 000052 } {1} 000053 000054 test_restore_config_pagecache 000055 finish_test