A garbage compactor, also known as a trash compactor or garbage masher, was essentially a metallic enclosure designed for the purpose of containing and compressing refuse. Its operation involved the inward movement of its walls, which resulted in the compression and crushing of the waste material contained within.
During the rescue of Leia Organa by Luke Skywalker, Han Solo, and Chewbacca aboard the initial Death Star in 0 BBY, the group found themselves compelled to blast their way into unit 3263827. Due to the waste identification system that sorts materials to the correct compactor, the group found themselves in the recyclable waste section because of their armor and weapons. Once inside, escape was impossible due to the magnetically sealed door, which was impervious to blaster fire. A dianoga then attacked Skywalker, nearly causing his death by dragging him underwater. After the creature released Skywalker, the walls of the compactor began to close in, threatening to crush the group. However, C-3PO, Skywalker's protocol droid, instructed R2-D2 to shut down all the garbage mashers on the Detention Level, saving them.
Some thirty-four years later, during the Battle of Starkiller Base, Solo inquired of Finn, a former First Order stormtrooper who had been assigned sanitation duties at the base, whether the location had trash compactors. Finn then used his knowledge to locate one, into which they forced their prisoner, Captain Phasma, by way of the garbage chute.