pi4j-v2
                                
                                
                                
                                    pi4j-v2 copied to clipboard
                            
                            
                            
                        Unmapping/remapping pins
If I create an IO config for a pin with
config = DigitalInput.newConfigBuilder(rpi4j).provider("pigpio-digital-input").id("pin-"+pinNumber).address(pinNumber)....
pin = rpi4j.create(config);
the name "pinX" is registered in the Registry and the pin works accordingly.
If I then want to disconnect the pin I call
pin.shutdown(rpi4j);
which seems to forward the disconnect to pigpio but doesn't unregister the IO in the Registry.
Any attempt to then create a new config with the same id creates an exception:
com.pi4j.io.exception.IOAlreadyExistsException: IO instance [pin14] already exists in the Pi4J runtime context; unable to create a new instance using this reserved id.
	at com.pi4j.provider.impl.ProviderProxyHandler.invoke(ProviderProxyHandler.java:99)
	at com.sun.proxy.$Proxy2.create(Unknown Source)
	at com.pi4j.context.Context.create(Context.java:309)
	at com.pi4j.internal.IOCreator.create(IOCreator.java:60)
	at com.pi4j.internal.IOCreator.create(IOCreator.java:101)
	at com.pi4j.internal.IOCreator.create(IOCreator.java:189)
        ...
The registry on the autoContext doesn't seem to have a way to remove things from it (it is a DefaultRegistry not RuntimeRegistry)
This is a good point. I just ran into it myself.
Is there is a possibility to support you to solve the issue?
Does this thread alive?
I see @eitch did a commit https://github.com/Pi4J/pi4j-v2/pull/198/files related to this topic.
I merged a PR, and i think it should be fine now since v2.2.0