An NDA can continue indefinitely or end on a predetermined date.
You can specify a date for the duty of non-disclosure (the responsibility of keeping the information confidential) to end. This date can be when the relationship between the two parties ends, or it can be when the information no longer needs to be confidential.
Also, the obligations created by an NDA can end if the confidential information becomes publicly known (through no fault of the receiving party).
For instance, imagine two inventors enter an NDA with a potential investor. The investor agrees to keep the details of the invention confidential until they can begin manufacturing and selling the new product. If one of the inventors were to give away the secrets of the invention during an interview with a journalist, the information would be considered public knowledge. In this case, the receiving party (the investor) wouldn’t be to blame and the NDA would be voidable.