Skip to content

Instantly share code, notes, and snippets.

@kmagiera
Created July 25, 2018 10:11
Show Gist options
  • Save kmagiera/43edea7f114ad8fae35cf73d442fda4d to your computer and use it in GitHub Desktop.
Save kmagiera/43edea7f114ad8fae35cf73d442fda4d to your computer and use it in GitHub Desktop.
import React from 'react';
import { View, Text, AppState } from 'react-native';
const SIZE = 1000000;
export default class DetailsScreen extends React.Component {
memory = new Array(SIZE).join('|');
interval = null;
state = { count: 1 };
componentDidMount() {
AppState.addEventListener('change', nextAppState => {
if (nextAppState === 'active') {
this.interval = setInterval(this.refresh, 1000);
} else {
clearInterval(this.interval);
}
});
this.interval = setInterval(this.refresh, 1000);
}
componentWillUnmount() {
clearInterval(this.interval);
}
refresh = () => {
this.setState({ count: this.state.count + 1 });
};
render() {
return (
<View>
<Text>
Allocated {SIZE} bytes, go back to see the memory gets retained
</Text>
<Text>Foreground time counter: {this.state.count} sec</Text>
</View>
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment