For EAD/AP (AOS is Pending category or (c)(9) eligibility after 180 days with first company):
Once you crossed 180 days with the employer that filed for your AOS, you can be out of job for as long as you like. However, USCIS may send you a RFE for I485J anytime. At that time, you need to show that you have a future job with same or similar category classification. These RFEs have a 90 day return window. Usually USCIS sends a RFE only when your FA PD is current. However, they can suddenly become efficient and send you a RFE if you happen to be on their radar.
It is better to be on a job with EAD/AP (AOS Pending) status and have a plan to submit I485J whenever it is required.
For H1B:
You have 60 days grace period. See
https://www.uscis.gov/archive/uscis-...-visa-programs