# Retained Memory Tips

**URL:** <https://community.particle.io/t/retained-memory-tips/38137>\
**Category:** Tutorials\
**Created:** [December 15, 2017, 6:39pm UTC](https://community.particle.io/t/retained-memory-tips/38137 "2017-12-15T18:39:38Z")\
**Posts on this page:** 1\
**Showing post:** 7

<div class="post-metadata">

**Author:** ![shanevanj](https://sea2.discourse-cdn.com/flex026/user_avatar/community.particle.io/shanevanj/32/21186_2.png) [@shanevanj](https://community.particle.io/u/shanevanj)\
**Post date:** [September 19, 2019, 9:09am UTC](https://community.particle.io/t/retained-memory-tips/38137/7 "2019-09-19T09:09:14Z")

</div>

You are missing what I am saying - I’m my view whether a battery is or isn’t connected - the **first** time the code is run - the value should be 0 - then after that point and as long as battery/power is connected - the value will be retained as its last set value.

Using the above example - with or without a battery connected the **first** time the code is run it is never 0. as expected it does increment from what ever value it first shows.

```auto
STARTUP(System.enableFeature(FEATURE_RETAINED_MEMORY)); 
retained int savedValue = 0; 
void setup() {
 Serial.begin(9600);
} 

void loop() { 
Serial.printlnf(“savedValue=%d”, savedValue++); 
delay(1000);
}

```

---

_[View the full topic](https://community.particle.io/t/retained-memory-tips/38137)._
