Just to get started, can you describe the spark version you are using and the language? It doesn't sound like you are using pyspark, however, problems arising from that can be different so I just want to be sure. As well, can you talk through the scenario under which you are dealing with this error? ie the order of operations for the transformations you are applying.
However, if you're set on getting a heap dump, probably the easiest way would be to just monitor an active application through the spark UI then go grab a heap dump from the executor java process when you notice one that's having problems.