"Data memory" - why do they use such an obscure name?
To try to differentiate it from the many other types of memory:
"Memory", "RAM" = PC volatile storage (infinite cycles.)
"EPROM", "EEPROM", "Flash" = PC BIOS non-volatile storage (thousands of cycles.)
"Aux Flash", "Data EEPROM" = PIC non-volatile data storage (robust but small, withstands many cycles)
"Data" or "Data Memory" = PIC volatile RAM (infinite cycles)
"Program" or "Program Memory" = PIC non-volatile code storage (which happens to be flash, limited to thousands of cycles.)
[MPLABX] should say how close each optimizer came to fitting in the allotted RAM.
While under the limits imposed by the particular PIC being compiled for, it will report this information as a summary:
Memory Summary:
Program space used BDh ( 189) of 2000h words ( 2.3%)
Data space used 14h ( 20) of 400h bytes ( 2.0%)
EEPROM space None available
Configuration bits used 5h ( 5) of 5h words (100.0%)
ID Location space used 4h ( 4) of 4h bytes (100.0%)
make[2]: Leaving directory 'C:/Users/me/foo/bar/ACTDSWT.X'
make[1]: Leaving directory 'C:/Users/me/foo/bar/ACTDSWT.X'
BUILD SUCCESSFUL (total time: 6s)
From this, I know that 0x14/0x400 data bytes are used or 2%, so 0x3EC remain.
Therefore, if I try to assign 0x400 more bytes, it will fail.
It can also report this in the dashboard as a visual "gauge":

But the moment program/data are exceeded, it fails to build with a message like:
"C:\Program Files\Microchip\xc8\v2.36\bin\xc8-cc.exe" -mcpu=16F15375 -Wl,-Map=dist/default/production/ACTDSWT.X.production.map -DXPRJ_default=default -Wl,--defsym=__MPLAB_BUILD=1 -mdfp="C:/Users/me/.mchp_packs/Microchip/PIC16F1xxxx_DFP/1.13.178/xc8" -fno-short-double -fno-short-float -O0 -fasmfile -maddrqual=ignore -mcodecov=ram -xassembler-with-cpp -mwarn=-3 -Wa,-a -msummary=-psect,-class,+mem,-hex,-file -ginhx32 -Wl,--data-init -mno-keep-startup -mno-osccal -mno-resetbits -mno-save-resetbits -mno-download -mno-stackcall -mdefault-config-bits -std=c99 -gdwarf-3 -mstack=compiled:auto:auto -Wl,--memorysummary,dist/default/production/memoryfile.xml -o dist/default/production/ACTDSWT.X.production.elf build/default/production/mcc_generated_files/device_config.p1 build/default/production/mcc_generated_files/mcc.p1 build/default/production/mcc_generated_files/pin_manager.p1 build/default/production/main.p1
main.c:33:: error: (1250) could not find space (400 bytes) for variable _baz
main.c:33:: warning: (1262) object "_baz" lies outside available data space
(908) exit status = 1
nbproject/Makefile-default.mk:186: recipe for target 'dist/default/production/ACTDSWT.X.production.hex' failed
make[2]: Leaving directory 'C:/Users/me/foo/bar/ACTDSWT.X'
nbproject/Makefile-default.mk:91: recipe for target '.build-conf' failed
make[1]: Leaving directory 'C:/Users/me/foo/bar/ACTDSWT.X'
nbproject/Makefile-impl.mk:39: recipe for target '.build-impl' failed
make[2]: *** [dist/default/production/ACTDSWT.X.production.hex] Error 1
make[1]: *** [.build-conf] Error 2
make: *** [.build-impl] Error 2
BUILD FAILED (exit value 2, total time: 2s)
From this message, we can tell that "baz" was supposed to be 400 bytes and could not be allocated. The only solution in this case is to comment-out or temporarily reduce "baz" and recompile until it succeeds.
Paid editions of the XC compiler should yield noticeable optimization savings, mostly in program size. But that won't help if trying to allocate a 1M buffer on a 1k chip, for instance.
Figure out how much data memory you need, then select a chip with more than that. Preferably twice as much, so there will be room to grow if the code changes during development, which it usually does. And is all that data memory really needed? Is it a mistake in defining the variable; i.e. should var[20]=0 really be var=20? Can it be simplified in some other way? Some PICs include provisions for connecting external data RAM chips. While complex, that is another possibility.
Note that when starting out, it is better to obtain smaller PICs first and work on small projects and slowly graduate to bigger projects. Because jumping into the complexity of bigger chips (with large memories) blindly can be astounding. This has caused some percentage of people to simply walk away from them in frustration. So do not let a large data requirement force you into using some big, overly-complex device if uncomfortable.