blob: bc4a707bff2bf7094f04ca7dd4642506f63f9e98 [file] [log] [blame]
drh09419b42011-11-16 19:29:17 +00001# 2011 November 16
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#
12# This file contains test cases for sqlite3_db_release_memory and
13# the PRAGMA shrink_memory statement.
14#
15
16set testdir [file dirname $argv0]
17source $testdir/tester.tcl
drh7416f2e2015-07-25 03:10:12 +000018test_set_config_pagecache 0 0
drh09419b42011-11-16 19:29:17 +000019
20unset -nocomplain baseline
21do_test shrink-1.1 {
22 db eval {
dan5d8341a2012-01-12 16:41:30 +000023 PRAGMA cache_size = 2000;
drh09419b42011-11-16 19:29:17 +000024 CREATE TABLE t1(x,y);
25 INSERT INTO t1 VALUES(randomblob(1000000),1);
26 }
drh905b82d2021-09-06 15:59:32 +000027 set ::baseline [sqlite3_memory_used]
drh8dd7a6a2015-03-06 04:37:26 +000028 # EVIDENCE-OF: R-58814-63508 The sqlite3_db_release_memory(D) interface
29 # attempts to free as much heap memory as possible from database
30 # connection D.
drh09419b42011-11-16 19:29:17 +000031 sqlite3_db_release_memory db
32 expr {$::baseline > [sqlite3_memory_used]+500000}
33} {1}
34do_test shrink-1.2 {
35 set baseline [sqlite3_memory_used]
36 db eval {
37 UPDATE t1 SET y=y+1;
38 }
39 expr {$::baseline+500000 < [sqlite3_memory_used]}
40} {1}
41do_test shrink-1.3 {
42 set baseline [sqlite3_memory_used]
43 db eval {PRAGMA shrink_memory}
44 expr {$::baseline > [sqlite3_memory_used]+500000}
45} {1}
46
drh7416f2e2015-07-25 03:10:12 +000047test_restore_config_pagecache
drh09419b42011-11-16 19:29:17 +000048finish_test