Adhoc Queries filling up plan cache
Following can be used to clean adhoc and prepared query plan cache . This is from Glenn Berry - Eight Different Ways to Clear the SQL Server Plan Cache

DBCC FREESYSTEMCACHE ('SQL Plans') 


It also says:


  “I would argue that running DBCC FREEPROCCACHE does not cause that much distress with a modern processor, even on a very busy OLTP system. It will cause a pretty minor CPU spike for a few seconds on most systems as the query plans get recompiled as they are executed. “


Following query can give adhoc queries in the plan cache

SELECT  DISTINCT 
        QCP.objtype
        ,MultipleQ.PlanCount
        ,qStat.query_hash
        ,sText.text AS QueryText
        ,size_in_bytes
        ,qStat.creation_time
FROM ( 
        SELECT query_hash,
               COUNT(query_hash) AS PlanCount
        FROM sys.dm_exec_query_stats
        GROUP BY query_hash
    ) AS MultipleQ
INNER JOIN sys.dm_exec_query_stats qStat ON MultipleQ.query_hash = qStat.query_hash
INNER JOIN sys.dm_exec_cached_plans  QCP
    ON QCP.plan_handle = qStat.plan_handle
CROSS APPLY sys.dm_exec_sql_text(qStat.sql_handle) AS sText
CROSS APPLY sys.dm_exec_query_plan(qStat.plan_handle) AS qp
WHERE PlanCount &gt; 1
AND QCP.objtype = 'Adhoc'
ORDER BY MultipleQ.PlanCount DESC


If you have Query Store you can use “Delete ad-hoc queries” as defined in 
Monitoring performance by using the Query Store

Enabling optimize for adhoc workloads can be found in  Kimberly Tripp - Plan cache and optimizing for adhoc workloads