Thanks for joining the forum.
bedmap should consume very little memory so this is definitely unexpected behavior. It sounds like you've met the requirements for inputs, and you're using --ec to be sure.
Could you report the version of bedmap you're using, please? bedmap --help will show the version number near the top.
We sometimes find cases where input files are formatted using Windows newlines. --ec should be able to pick that up as well though. Would it be possible for you to post these files for download so we can take a close look?
Update: I've run the same sequence of commands you show above using 30 GB inputs without issue. bedmap will read into memory up to a chromsome's worth of data in the odd event that everything on that chromosome in your second file overlaps 1 entry in the first (reference) file. Even in this very odd scenario, there shouldn't be any way to exhaust the memory you've allocated. Under typical uses, you should only see memory running at perhaps 30 MB. We're very interested in following up on this potential issue if we can.