Device memory info

I would like showing current device memory info via import DeviceInfo from ‘@amzn/react-native-device-info’;

I tyr use Sync but I have 0 all time

    const [total, setTotal] = useState<number>(0);
    const [used, setUsed] = useState<number>(0);
    const [free, setFree] = useState<number>(0);

    useEffect(() => {
      const updateMemory = () => {
        try {
          const totalMem = DeviceInfo.getTotalMemorySync(); // bytes
          const usedMem = DeviceInfo.getUsedMemorySync(); // bytes
          setTotal(Math.round(totalMem / (1024 * 1024)));
          setUsed(Math.round(usedMem / (1024 * 1024)));
          setFree(Math.round((totalMem - usedMem) / (1024 * 1024)));
        } catch (e) {
          console.warn('MemoryMonitor error:', e);
        }
      };
      updateMemory(); // first run
      const interval = setInterval(updateMemory, 5000); // every 5 sec
      return () => clearInterval(interval);
    }, []);

and async but I have 0 all time

    const [total, setTotal] = useState<number>(0);
    const [used, setUsed] = useState<number>(0);
    const [free, setFree] = useState<number>(0);

    const fetchMemory = async () => {
      try {
        const totalMem = await DeviceInfo.getTotalMemory(); // bytes
        const usedMem = await DeviceInfo.getUsedMemory(); // bytes

        setTotal(totalMem);
        setUsed(usedMem);
        setFree(totalMem - usedMem);
      } catch (e) {
        console.warn('MemoryMonitor error:', e);
      }
    };

    useEffect(() => {
      fetchMemory(); 
      const interval = setInterval(fetchMemory, 5000); 
      return () => clearInterval(interval);
    }, []);

Have you any idea, how can I to show current device memory info?

Hi @Viktor_Kravchuk ,

Our team will take a look at your request and get back soon.

Thanks,
Rohit

Hi @Viktor_Kravchuk ,

Can you please explain why the device memory info is required and what you intent to do with it?

Thanks,
Rohit

I have performance issues. Sometimes I have out of memory and app is crashing. I would like to show for each page information about memory status on production mode.

Hi @Viktor_Kravchuk ,

Checking in. Is this still an issue for you and if yes, is it a blocker for your development?

Thanks,
Rohit

I would like to use this functionality for deeply understanding “bottleneck” of memory usage. It is not blocker, however nice to have