@Test
	public void testClearWithClearContext() throws CodeUnitInsertionException,
			ContextChangeException, CancelledException, IOException {
		DBTraceRegisterContextManager ctxManager = b.trace.getRegisterContextManager();
		Register r4 = b.language.getRegister("r4");
		RegisterValue rvOne = new RegisterValue(r4, BigInteger.ONE);

		TraceData d4000;
		TraceData d4004;
		TraceInstruction i4008;
		try (Transaction tx = b.startTransaction()) {
			d4000 = b.addData(0, b.addr(0x4000), IntegerDataType.dataType, b.buf(1, 2, 3, 4));
			d4000.setEndSnap(9);
			d4004 = b.addData(0, b.addr(0x4004), IntegerDataType.dataType, b.buf(5, 6, 7, 8));
			d4004.setEndSnap(5);
			i4008 = b.addInstruction(0, b.addr(0x4008), b.host, b.buf(0xf4, 0));
			i4008.setEndSnap(9);

			// Clear one of the data before a context space is created
			manager.definedUnits()
					.clear(Lifespan.ALL, b.range(0x4004, 0x4004), true,
						TaskMonitor.DUMMY);

			i4008.setRegisterValue(rvOne);
		}
		assertEquals(rvOne, ctxManager.getValue(b.language, r4, 0, b.addr(0x4008)));
		assertEquals(rvOne, ctxManager.getValue(b.language, r4, 7, b.addr(0x4008)));

		try (Transaction tx = b.startTransaction()) {
			manager.instructions()
					.clear(Lifespan.ALL, b.range(0x0000, -0x0001), true,
						TaskMonitor.DUMMY);
		}
		assertNull(ctxManager.getValue(b.language, r4, 0, b.addr(0x4008)));

		b.trace.undo();
		assertEquals(rvOne, ctxManager.getValue(b.language, r4, 0, b.addr(0x4008)));
		assertEquals(rvOne, ctxManager.getValue(b.language, r4, 7, b.addr(0x4008)));

		try (Transaction tx = b.startTransaction()) {
			manager.instructions()
					.clear(Lifespan.span(7, 7), b.range(0x0000, -0x0001), true,
						TaskMonitor.DUMMY);
		}
		assertNull(ctxManager.getValue(b.language, r4, 7, b.addr(0x4008)));
		assertEquals(rvOne, ctxManager.getValue(b.language, r4, 6, b.addr(0x4008)));
	}
This test is interesting because the pointer type def causes an update to the data type
settings <em>while the unit is still being created</em>. This will invalidate the trace's
caches. All of them, including the defined data units, which can become the cause of many
timing issues.
Ghidra/Debug/Framework-TraceModeling/src/test/java/ghidra/trace/database/listing/DBTraceCodeManagerTest.java