When facing a Destroyer or Fast attack craft, there's something useful that can help you keep from being depth charged. It's a two part little trick, and yeah, it doesn't always work but most of the time it will. It may buy you the time you need to get away. Here's what you do.
When facing a destroyer, corvette, or fast attack craft, stay around 10 m with your periscope up. You want them to see you. The destroyers will turn to you, heading at you. Next, you fire two torpedos, one on each side of the attacking destroyer. This will cause it to evade, and usually it'll stop dropping depth charges. If it doesn't evade, the Destroyer will eat the torpedo and you get one more kill.
IF the destroyer evades, quickly crash dive to 150 m to avoid the destroyer should it double back on you. This will buy you the time to hide below it's sonar range.