void deleteBlocks(final List<MemoryBlock> blocks) {

		if (blocks == null || blocks.size() <= 0) {
			return;
		}

		StringBuffer blockNames = new StringBuffer();
		AddressSet set = new AddressSet();
		for (int i = 0; i < blocks.size(); i++) {
			MemoryBlock block = blocks.get(i);
			blockNames.append(block.getName());
			if (i < blocks.size() - 1) {
				blockNames.append(", ");
			}
			set.addRange(block.getStart(), block.getEnd());
		}
		String msg =
			"Do you really want to delete the Memory Block(s)\n" + "   " + blockNames + "  ?";
		Listing listing = program.getListing();
		InstructionIterator iter = listing.getInstructions(set, true);

		if (iter.hasNext()) {
			msg = "Code Units exist in selected block(s).\n" + "Do you want to continue?";
		}
		else {
			DataIterator dIter = listing.getDefinedData(set, true);
			if (dIter.hasNext()) {
				msg = "Code Units exist in selected block(s).\n" + "Do you want to continue?";
			}
		}

		int option = -1;

		option = OptionDialog.showOptionDialog(plugin.getMemoryMapProvider().getComponent(),
			"Delete Memory Block?", msg, "Yes", OptionDialog.QUESTION_MESSAGE);

		if (option == OptionDialog.CANCEL_OPTION) {
			return;
		}

		Address[] addresses = new Address[blocks.size()];
		for (int i = 0; i < blocks.size(); i++) {
			MemoryBlock block = blocks.get(i);
			addresses[i] = block.getStart();
		}
		DeleteBlockCmd cmd = new DeleteBlockCmd(addresses, command -> {
			// don't care
		});

		tool.executeBackgroundCommand(cmd, program);
	}
Delete the list of memory blocks.
@param blocks list of memory blocks to be removed
Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/memory/MemoryMapManager.java